Skip to content

Commit 1927cb1

Browse files
authored
Prevent tab focus on mousedown (#4239)
Co-authored-by: Simone Todaro <[email protected]>
1 parent 2ddfff2 commit 1927cb1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/ui/src/tabs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ function handleTab(el, Alpine) {
105105
'@keydown.up.prevent.stop'() { this.$focus.within(this.$data.__activeTabs()).withWrapAround().prev() },
106106
'@keydown.left.prevent.stop'() { this.$focus.within(this.$data.__activeTabs()).withWrapAround().prev() },
107107
':tabindex'() { return this.$tab.isSelected ? 0 : -1 },
108+
// This is important because we want to only focus the tab when it gets focus
109+
// OR it finished the click event (mouseup). However, if you perform a `click`,
110+
// then you will first get the `focus` and then get the `click` event.
111+
// See https://github.com/tailwindlabs/headlessui/pull/1192
112+
'@mousedown'(event) { event.preventDefault() },
108113
'@focus'() {
109114
if (this.$data.__manualActivation) {
110115
this.$el.focus()

0 commit comments

Comments
 (0)