-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Remove LastFocus from Block Editor store in favor of useLastFocus #57557
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
Conversation
Adds useLastFocus in the utils to store a lastFocus ref and a setLastFocus for setting the ref.
|
Size Change: +170 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
Mamaduka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeryj, the APIs didn't make it into a stable WP release, so I think removing them and skipping deprecation is safe.
| * | ||
| * @return {Object} Object with a lastFocus ref and setLastFocus. | ||
| */ | ||
| const lastFocus = createRef(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, that is not a good approach because this is a global singleton, meaning that if you have multiple block editors in the same page, you'll end up with conflicts (they'll be sharing the same ref)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't consider multiple block editors on one page. Do you have any recommended routes to explore? I'll look at it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar enough with what we're trying to achieve here but a private selector/action could work without changing any logic.
What?
Adds useLastFocus in the utils to store a lastFocus ref and a setLastFocus for setting the ref.
Why?
getLastFocus/setLastFocusfrom the public API per request.How?
Adds a
useLastFocusto the Block Editor utils as a global Ref that can be set like:Then retrieved via:
Testing Instructions for Keyboard
There should be no change from trunk. This mostly impacts pressing the Escape toolbar