-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Editor: Fix block highlight rendering after block is moved #23425
Changes from 12 commits
ebd76f5
b2e8e48
4654809
27af1ce
1bd4189
6e2e085
239e07a
c444726
daea2b5
e2fb3f1
3af7855
2473ea4
76a3dbd
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 |
---|---|---|
|
@@ -35,11 +35,27 @@ function focusFirstTabbableIn( container ) { | |
} | ||
|
||
function useIsAccessibleToolbar( ref ) { | ||
/* | ||
* By default, we'll assume the starting accessible state of the Toolbar | ||
* is true, as it seems to be the most common case. | ||
* | ||
* Transitioning from an (initial) false to true state causes the | ||
* <Toolbar /> component to mount twice, which is causing undesired | ||
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. Mount or render? 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. mount :) 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 wonder if this is still needed after the adjustments I made? 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 think so. From our debugging, the Toolbar was double mounting regardless of the |
||
* side-effects. These side-effects appear to only affect certain | ||
* E2E tests. | ||
* | ||
* This was initial discovered in this pull-request: | ||
* https://github.com/WordPress/gutenberg/pull/23425 | ||
*/ | ||
const initialAccessibleToolbarState = true; | ||
|
||
// By default, it's gonna render NavigableMenu. If all the tabbable elements | ||
// inside the toolbar are ToolbarItem components (or derived components like | ||
// ToolbarButton), then we can wrap them with the accessible Toolbar | ||
// component. | ||
const [ isAccessibleToolbar, setIsAccessibleToolbar ] = useState( false ); | ||
const [ isAccessibleToolbar, setIsAccessibleToolbar ] = useState( | ||
initialAccessibleToolbarState | ||
); | ||
|
||
const determineIsAccessibleToolbar = useCallback( () => { | ||
const tabbables = focus.tabbable.find( ref.current ); | ||
|
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.
Why are we toggling block highlight in an effect rather than at the reducer level? For a SELECT_BLOCK action etc., the highlight state should change immediately. Cc @youknowriad.
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 agree that if we can do it automatically on the reducer, it's better and avoid an extra rerenders for all components.