Popper
Examples
hover
click
focus
right click
placement
import { ref } from 'vue';
export default {
setup: () => {
const placements = [
'top-start',
'top',
'top-end',
'bottom-start',
'bottom',
'bottom-end',
'left-start',
'left',
'left-end',
'right-start',
'right',
'right-end',
];
const pls = ref(placements[0]);
const renderType = ref('btn');
const showArrow = ref(true);
const renderSlice = (n: 0 | 3 | 6 | 9) =>
placements.slice(n, n + 3).map((plsKey) => (
<dv-button
key={plsKey}
size="xs"
data-pls={plsKey}
onClick={() => (pls.value = plsKey)}
type={plsKey === pls.value ? 'primary' : 'neutral'}
>
{plsKey}
</dv-button>
));
return () => (
<div class="w-full">
<div class="flex justify-center space-x-3 mb-1">
<dv-button onClick={() => (renderType.value = 'btn')}>
button
</dv-button>
<dv-button onClick={() => (renderType.value = 'div')}>div</dv-button>
<input
type="checkbox"
checked={showArrow.value}
onChange={(e) => {
showArrow.value = e.target.checked;
}}
/>
</div>
<dv-divider />
<div class="h-56 relative flex items-center justify-center">
<dv-popper
content={() => (
<div>
This is a <strong>tooltip</strong>
</div>
)}
open
placement={pls.value}
hideArrow={!showArrow.value}
>
{renderType.value === 'btn' ? (
<dv-button size="sm">button</dv-button>
) : (
<div class="w-8 h-8 flex items-center justify-center bg-red-400">
div
</div>
)}
</dv-popper>
{/* top */}
<div class="absolute top-0 w-full flex justify-center space-x-2">
{renderSlice(0)}
</div>
{/* right */}
<div class="absolute right-0 h-full flex flex-col justify-center space-y-2">
{renderSlice(9)}
</div>
{/* bottom */}
<div class="absolute bottom-0 w-full flex justify-center space-x-2">
{renderSlice(3)}
</div>
{/* left */}
<div class="absolute left-0 h-full flex flex-col justify-center space-y-2">
{renderSlice(6)}
</div>
</div>
</div>
);
},
};
tsx
render props
jsx slots
template slots
Popper
Attributes
name | description | type | default |
---|---|---|---|
content | popper content | any, function | - |
open | popper open status | boolean | - |
placement | popper placement | Placement | auto |
disableTeleport | disable popper node teleport to body | boolean | false |
disabled | disable popper | boolean | true |
onChange | emitted whe popper status change | function | - |
triggerAction | the action to tigger popper | contextMenu, hover, click, focus | hover |
outsideCloseable | click outside to close popper | boolean | true |
escapeCloseable | press escape key to close popper | boolean | true |
Slots
name | description |
---|---|
default | popper reference |
content | popper content |