Multistep modal loses focus
- Dominant language
- JavaScript
- Stars
- 226
- Forks
- 235
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 19
Description
We have a few multistep modals, including `FieldKeyNew`, `DatasetNew`, and `ProjectEnableEncryption`. When the user moves from step to step, the modal element (or a descendant element) should remain focused. This is needed so that the user is able to use the escape key to hide the modal after moving from one step to the next.
Outdated implementation details
Right now we use the `refocus()` method of the `Modal` component to implement this; the method is called after a `focusout` event. (By having `Modal` handle this, each individual modal component — for example, `FieldKeyNew` — does not need to refocus the modal element.) This approach works in Chrome, but it doesn't seem to work in Firefox.
To reproduce:
1. Navigate to the App Users tab of a project.
2. Click the create button.
3. Enter a nickname.
4. Press enter.
5. The modal should show that the app user was created successfully. However, the modal has lost focus: the escape key no longer hides the modal.
More implementation details
It does not seem like `refocus()` is being called. Is there no `focusout` event from the input element before it is removed? We could use the `updated` hook instead of `focusout`, but we also had an issue with that approach: see 801c1e76be8ae0b45761ac8c51ff52ad032dad0d. Maybe we could combine an `updated` hook with `setTimeout()`?
Interestingly, if instead of pressing enter, the user clicks the Create button, the modal does not lose focus. There does not seem to be a `focusout` event from the Create button, but there is a `focusout` event from the input element, ~which causes `refocus()` to be called~.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.