Skip to content

Commit

Permalink
trigger "outside click" behaviour on mousedown
Browse files Browse the repository at this point in the history
Fixes: #95
  • Loading branch information
RobinMalfait committed Jan 29, 2021
1 parent 80402e7 commit ab75bc6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/@headlessui-react/src/components/listbox/listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export function Listbox<
if (!event.defaultPrevented) buttonRef.current?.focus({ preventScroll: true })
}

window.addEventListener('click', handler)
return () => window.removeEventListener('click', handler)
window.addEventListener('mousedown', handler)
return () => window.removeEventListener('mousedown', handler)
}, [listboxState, optionsRef, buttonRef, d, dispatch])

const propsBag = React.useMemo<ListboxRenderPropArg>(
Expand Down
4 changes: 2 additions & 2 deletions packages/@headlessui-react/src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ export function Menu<TTag extends React.ElementType = typeof DEFAULT_MENU_TAG>(
if (!event.defaultPrevented) buttonRef.current?.focus({ preventScroll: true })
}

window.addEventListener('click', handler)
return () => window.removeEventListener('click', handler)
window.addEventListener('mousedown', handler)
return () => window.removeEventListener('mousedown', handler)
}, [menuState, itemsRef, buttonRef, dispatch])

const propsBag = React.useMemo(() => ({ open: menuState === MenuStates.Open }), [menuState])
Expand Down
4 changes: 2 additions & 2 deletions packages/@headlessui-vue/src/components/listbox/listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export const Listbox = defineComponent({
if (!event.defaultPrevented) buttonRef.value?.focus({ preventScroll: true })
}

window.addEventListener('click', handler)
onUnmounted(() => window.removeEventListener('click', handler))
window.addEventListener('mousedown', handler)
onUnmounted(() => window.removeEventListener('mousedown', handler))
})

// @ts-expect-error Types of property 'dataRef' are incompatible.
Expand Down
4 changes: 2 additions & 2 deletions packages/@headlessui-vue/src/components/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ export const Menu = defineComponent({
if (!event.defaultPrevented) buttonRef.value?.focus({ preventScroll: true })
}

window.addEventListener('click', handler)
onUnmounted(() => window.removeEventListener('click', handler))
window.addEventListener('mousedown', handler)
onUnmounted(() => window.removeEventListener('mousedown', handler))
})

// @ts-expect-error Types of property 'dataRef' are incompatible.
Expand Down

0 comments on commit ab75bc6

Please sign in to comment.