[Vue] - Tabs not working properly when conditionally updating the `selected-index` prop from the `change` event
See original GitHub issueWhat package within Headless UI are you using?
What version of that package are you using?
v1.7.1
What browser are you using?
Chrome Latest
Reproduction URL
https://codesandbox.io/s/awesome-thompson-ytuh1o?file=/src/App.vue
Describe your issue
I have forms within TabPanel
and I want to implement a “Discard changes” confirmation before switching to another tab, if there are unsaved changes.
I tried implementing this with a custom modal and the built in one, but it doesn’t work properly.
When I press Cancel, instead of getting back to the browser, the click event triggers again and again and it enters a permanent loop.
What I’m trying to use is a controlled component, I’m using the change
event to conditionally determine whether or not the user should move to the new tab.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Hey!
I reworked the internals of the
Tab
component a bit so that it only changes tabs when you use your arrow keys or when you actually click it. Not when you are just “focusing” it. This was an (incorrect) implementation detail that should now be fixed.This should be fixed by #1887, and will be available in the next release.
You can already try it using:
npm install @headlessui/react@insiders
.npm install @headlessui/vue@insiders
.I just ran into this on the React side of things and the best way I found to get it working was to use the
manual
option for the Tab.Group. This seems to work in your Vue example even though it leaves focus on the wrong tab in the end. That seems like an easier problem to solve though…