-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Implement roving tabindex on the header toolbar #22354
Changes from 7 commits
fdbba33
8ca8540
2cd9f8c
f4aabc9
ffa948b
9ae1761
d18eeaf
a759470
47a9bcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,13 @@ import { withSelect, withDispatch } from '@wordpress/data'; | |
import { compose } from '@wordpress/compose'; | ||
import { displayShortcut } from '@wordpress/keycodes'; | ||
import { redo as redoIcon } from '@wordpress/icons'; | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
function EditorHistoryRedo( { hasRedo, redo } ) { | ||
function EditorHistoryRedo( { hasRedo, redo, innerRef, ...props } ) { | ||
return ( | ||
<Button | ||
{ ...props } | ||
ref={ innerRef } | ||
icon={ redoIcon } | ||
label={ __( 'Redo' ) } | ||
shortcut={ displayShortcut.primaryShift( 'z' ) } | ||
|
@@ -24,11 +27,15 @@ function EditorHistoryRedo( { hasRedo, redo } ) { | |
); | ||
} | ||
|
||
export default compose( [ | ||
const EnhancedEditorHistoryRedo = compose( [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered refactoring this and other similar components ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't played with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing👍 |
||
withSelect( ( select ) => ( { | ||
hasRedo: select( 'core/editor' ).hasEditorRedo(), | ||
} ) ), | ||
withDispatch( ( dispatch ) => ( { | ||
redo: dispatch( 'core/editor' ).redo, | ||
} ) ), | ||
] )( EditorHistoryRedo ); | ||
|
||
export default forwardRef( ( props, ref ) => ( | ||
<EnhancedEditorHistoryRedo { ...props } innerRef={ 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.
I'm flagging this for myself to test what happens with focus when you change viewport of your browser and this button disappears when focused. I know it's an edge case and it might be an issue before but I'm simply curious :)
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 tested it. When one of the blocks were selected before, then focus moves to the selected block 🙃
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 was wrong, the blinking cursor tricked me, so the focus gets removed, and when you tab it gets restored to one of the items in the toolbar, not that bad I guess. Could Reakit move focus automatically to the next/previous item in such case or would be too far in what it should do? :)
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.
In the first iterations, Reakit's
Composite
(and thereforeToolbar
) automatically moved focus to the next/previous item when the current focused item got unmounted. Later it was changed so the previously focused item would get focus, like when you open and close a new tab on Chrome. But I haven't found enough material to support any of those approaches, and this was making the code even more complex for little gain, so I reverted it.For now,
toolbar.currentId
is still set to the previously focused item, but it doesn't automatically move focus. It's up to the user to decide what to do, but I do plan to revisit it in the future.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 would expect it’s going to be tricky to handle 😅 A similar challenge is when you click a button and it should become disabled, like when triggering undo until there is nothing to undo.
In this particular case, I assume it’s fine to clean up internally Reakit’s state - that is the current value and leave the rest (focus) of handling to the implementer.