Dialog: focus moved to first focusable element when changing tabs in modal (Firefox) → Dialog: Track last focused element instead of always focusing the first tabbable element
bug → feature
This happens because Firefox focuses the document when showing the page. We need to shift focus back to the dialog, so the only option is either put focus back on the first element or the element that had focus when the page was hidden. We can probably track which element had focus to make this better, but this is working as intended based on what Firefox is doing.
- Create a property to store which element currently has focus.
- Set this to
null on create.
- When determining which element to focus, first check if we have a stored element.
- On close, reset the property to
This should give us consistent behavior whenever the dialog loses focus (regardless of how that happens).