Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore focus to item that was focused before opening palette #33

Merged
merged 3 commits into from
Feb 11, 2023

Conversation

rouilj
Copy link
Contributor

@rouilj rouilj commented Feb 7, 2023

When the palette opens, it steals focus from the underlying page. This change records the focused element before opening the modal. Then on onClose it restores the focus to the element.

This happens regardless of the state of hotkeysGlobal, but is only really noticeable when you invoke command-pal
from a control.

John P. rouillard added 2 commits February 6, 2023 20:47
When the palette opens, it steals focus from the underlying page.
This change records the focused element before opening the modal.
Then on onClose it restores the focus to the element.
Activating the palette using the mobile button doesn't set focusedElement
from document.activeElement.

Even if it did, the button becomes the activeElement. Not exactly useful.

Set up a focus handler that looks at event.relatedTarget and use the
relatedTarget as the focusedElement if it can be focused. If
relatedTarget is null, use document.body.

also if focusedElement is falsy, console.error it.

Also added a period at the end of the title for the button in MobileButton.
It makes voice reading work better.
Copy link
Owner

@benwinding benwinding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay focusedElement is making sense now 😅
Fantastic idea, that's something that's bugged me for a while

@rouilj
Copy link
Contributor Author

rouilj commented Feb 11, 2023

Arguably it could be toBeFocusedElement but that's a little wordy.

@benwinding benwinding merged commit 7b0ac7b into benwinding:master Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants