Group placeholder: broken keyboard interaction and duplicate props #49758
Labels
[Focus] Accessibility (a11y)
Changes that impact accessibility and need corresponding review (e.g. markup changes).
[Package] Block library
/packages/block-library
[Type] Bug
An existing feature does not function as intended
[Type] Regression
Related to a regression in the latest release
Description
Seems to me this bug originates from #43496.
When inserting a Group block, the related placeholder is initially shown. Initial focus, keyboard interaction, and tooltips displaying appear to be completely broken. For example:
Initial focus is on the block wrapper. But the first button within the placeholder shows its tooltip, even if the button is not focused:
When pressing the Right arrow key, focus should go to the first button. Actually, the wrapper isn't focused any longer but the first button doesn't receive focus. Instead, focus appears to go somewhere in the middle, on a non-visible element. The first button tooltip is still shown, even if the button isn't focused:
Navigating with the arrow keys and the Tab key surfaces more unexpected / broken behaviiors. I made a GIF to better illustrate:
Root cause:
To my understanding, in #43496
blockProps
are passed 'as is' to the Placeholder wrapper, the only change is an additional class namerole=document
aria-label
data-*
attributes are duplicatedOther props that aren't rendered in the DOM are duplicated as well. For example the
ref
prop, which seems far from ideal. Not sure what may happen with the sameref
passed to twoneted components.This ref is actually a st of merged refs, including some refs that are used for hooks like
useFocusFirstElement
. Thus, some behaviors depending on these hooks is inevitably brokend eg. focus management.Screenshot of the two wrappers DOM, wee all the duplicated attributes:
To my understanding, the
blockProps
that come fromuseBlockProps
are meant to be exclusively used for the Block wrapper. Using these props on an extra wrapper seems less than ideal. That breaks expected interaction and semantics.If the only goal of the changes from #43496 wa to set the class names on the extra wrapper, then only the class names should be passed.
I'd also recommend to double check if there are other cases where the
blockProps
are passed to extraneous components / elements.Worth noting that in WordPress 5.9 the Group placeholder was very similar to the current one and it worked fine, simply because there was no extra wrapper:
Pinging a few people who may know more about this implementation:
@ramonjd, @tellthemachines, @youknowriad
Lastly: when a placeholder contains focusable elements, initial focus should to the first focusable element. See for example the Columns block.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: