Comments (5)
Hey!
The Dialog should already restore focus to the correct element once it closes without you having to do anything special.
The reproduction URL points to our template, can you update your reproduction URL so that we can take a look?
from headlessui.
Whoops! Try this link
from headlessui.
Hey!
So this is actually intended behavior, as @RobinMalfait suggested. When the dialog is closed and unmounts, Headless UI automatically restores focus to the element that was focused at the point the dialog was opened.
In your particular use-case this focus restoration is happening basically at the exact same time as the code in your afterLeave
callback, and Headless UI just happens to be winning out. You can fix this by delaying the focus of your input by one macrotask, which you can do using a setTimeout()
:
afterLeave={() => {
setTimeout(() => inputRef.current.focus())
}}
Hope that helps!
from headlessui.
@reinink Thanks! I had got it working with setTimeout
having a delay specified, but I didn't realize it had a no-args call for one-macrotask as well, that's useful.
One interesting bit - this is working for me in the web browser (chrome), but not in Electron, any ideas?
from headlessui.
This seems to be the root issue: electron/electron#28163
from headlessui.
Related Issues (20)
- [a11y]: Checkbox does not submit form on enter HOT 3
- First up/down arrow key press not switching items on static Combobox options HOT 1
- Using `null` as the value of a combobox option no longer works in @headlessui/vue v1.7.17 HOT 3
- Combobox: [email protected] breaks activeOption HOT 4
- [a11y]: Listbox does not submit form on enter HOT 2
- Switch component cannot stop propagation HOT 2
- Portal doesn't work in [email protected] after clientside navigation between pages. HOT 2
- Always render hidden inputs HOT 1
- ListboxButtons cause hydration errors in Nuxt HOT 3
- Dialog causes layout reflow which causes bad performance for large DOM trees HOT 1
- Warping transition while using overflow HOT 1
- Vue warn about getters not being side-effect free HOT 5
- The Menu component is not being propagated the touch event to the parent, so the Menu does not close automatically as expected. HOT 4
- [Dialog] Leave transition not working when using `:unmount="false"` (vue)
- Combobox `disabled` attribute not disabling hidden inputs HOT 1
- Tabs: `selectedIndex` is not selecting the correct tab HOT 3
- Combobox active item should loop
- Transition no longer maintaining class specified in enterTo at end of transition. HOT 4
- Combobox should navigate to first element when pressing arrow down HOT 3
- Aria-describedby for listbox hidden inputs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from headlessui.