Skip to content

Commit

Permalink
Prevent closing the Combobox component when clicking inside the scr…
Browse files Browse the repository at this point in the history
…ollbar area (#3104)

* prevent closing `Combobox` when clicking inside the scrollbar area

* update changelog
  • Loading branch information
RobinMalfait committed Apr 16, 2024
1 parent 004b8dc commit 9f44656
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `immediate` prop to `<Combobox />` for immediately opening the Combobox when the `input` receives focus ([#2686](https://github.com/tailwindlabs/headlessui/pull/2686))
- Add `virtual` prop to `Combobox` component ([#2779](https://github.com/tailwindlabs/headlessui/pull/2779))

### Fixed

- Prevent closing the `Combobox` component when clicking inside the scrollbar area ([#3104](https://github.com/tailwindlabs/headlessui/pull/3104))

## [1.7.20] - 2024-04-15

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions packages/@headlessui-vue/src/components/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,15 @@ export let ComboboxOptions = defineComponent({
},
})

/**
* Prevent focus from being lost if the user clicks on the scrollbar.
* Otherwise the `ComboboxInput` will lose focus and the combobox will
* close.
*/
function handleMouseDown(event: MouseEvent) {
event.preventDefault()
}

return () => {
let slot = { open: api.comboboxState.value === ComboboxStates.Open }
let ourProps = {
Expand All @@ -1380,6 +1389,7 @@ export let ComboboxOptions = defineComponent({
ref: api.optionsRef,
role: 'listbox',
'aria-multiselectable': api.mode.value === ValueMode.Multi ? true : undefined,
onMousedown: handleMouseDown,
}
let theirProps = omit(props, ['hold'])

Expand Down

0 comments on commit 9f44656

Please sign in to comment.