Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep <Combobox /> open when clicking in scrollbar on <ComboboxOptions> #3249

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add ability to render multiple `<Dialog />` components at once (without nesting them) ([#3242](https://github.com/tailwindlabs/headlessui/pull/3242))

### Fixed

- Keep `<Combobox />` open when clicking in scrollbar on `<ComboboxOptions>` ([#3249](https://github.com/tailwindlabs/headlessui/pull/3249))
RobinMalfait marked this conversation as resolved.
Show resolved Hide resolved

## [2.0.4] - 2024-05-25

### Fixed
Expand Down
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 because the `click` never fires.
RobinMalfait marked this conversation as resolved.
Show resolved Hide resolved
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
Loading