Skip to content

Commit

Permalink
keep <Combobox /> open when clicking in scrollbar on `<ComboboxOpti…
Browse files Browse the repository at this point in the history
…ons>`
  • Loading branch information
RobinMalfait committed May 28, 2024
1 parent e8c7661 commit 3d03601
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/@headlessui-react/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,18 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
actions.setActivationTrigger(ActivationTrigger.Pointer)
})

// When clicking inside of the scrollbar then a `click` will be triggered on
// the focusable element _below_ the scrollbar. If you use a `<Combobox>`
// inside of a `<Dialog>`, then clicking in the scrollbar of the
// `<ComboboxOptions>` will move focus to the `<Dialog>` which blurs the
// `<ComboboxInput>` which closes the `<Combobox>`.
//
// Preventing this default behavior in the `mousedown` event (which happens
// before `click`) will prevent this issue becaus the `click` never fires.
let handleMouseDown = useEvent((event: ReactMouseEvent) => {
event.preventDefault()
})

let ourProps = mergeProps(anchor ? getFloatingPanelProps() : {}, {
'aria-labelledby': labelledBy,
role: 'listbox',
Expand All @@ -1688,6 +1700,7 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
'--button-width': useElementSize(data.buttonRef, true).width,
} as CSSProperties,
onWheel: handleWheel,
onMouseDown: handleMouseDown,
})

// Map the children in a scrollable container when virtualization is enabled
Expand Down

0 comments on commit 3d03601

Please sign in to comment.