fix(menu): prevent dropdown from closing when cursor crosses offset gap (#2367)
This commit is contained in:
parent
62eb72c9f7
commit
d7722d0193
|
|
@ -68,9 +68,11 @@ defineSlots<{
|
|||
|
||||
const initialMount = ref(false)
|
||||
const open = ref(false)
|
||||
|
||||
const dropdown = ref<HTMLElement>()
|
||||
const dropdownMenu = ref<HTMLElement>()
|
||||
const dropdownPosition = ref({x: 0, y: 0})
|
||||
const dropdownMenuOffset = computed(() => 4)
|
||||
|
||||
function close() {
|
||||
open.value = false
|
||||
|
|
@ -87,7 +89,7 @@ async function updatePosition() {
|
|||
placement: 'bottom-end',
|
||||
strategy: 'absolute',
|
||||
middleware: [
|
||||
offset(4),
|
||||
offset(dropdownMenuOffset.value),
|
||||
autoPlacement({
|
||||
allowedPlacements: ['bottom-end', 'top-end', 'bottom-start', 'top-start'],
|
||||
padding: 8,
|
||||
|
|
@ -102,6 +104,7 @@ async function updatePosition() {
|
|||
const dropdownMenuStyle = computed(() => ({
|
||||
left: `${dropdownPosition.value.x}px`,
|
||||
top: `${dropdownPosition.value.y}px`,
|
||||
'--hover-offset': `${dropdownMenuOffset.value}px`,
|
||||
}))
|
||||
|
||||
function toggleOpen() {
|
||||
|
|
@ -129,6 +132,12 @@ onClickOutside(dropdown, (e) => {
|
|||
position: relative;
|
||||
}
|
||||
|
||||
.dropdown-menu::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: calc(var(--hover-offset) * -1);
|
||||
}
|
||||
|
||||
.dropdown-menu {
|
||||
min-inline-size: 12rem;
|
||||
position: absolute;
|
||||
|
|
|
|||
Loading…
Reference in New Issue