-
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
Use composite pattern to improve keyboard navigation on the inserter #23610
Changes from 3 commits
85a2a0c
ee899f9
c682202
506de60
595010e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Composite, useCompositeState } from 'reakit'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -14,16 +19,30 @@ function BlockTypesList( { | |
onSelect, | ||
onHover = () => {}, | ||
children, | ||
label, | ||
} ) { | ||
const composite = useCompositeState(); | ||
const normalizedItems = includeVariationsInInserterItems( items ); | ||
const orderId = normalizedItems.reduce( | ||
( acc, item ) => acc + '--' + item.id, | ||
'' | ||
); | ||
|
||
return ( | ||
/* | ||
* Disable reason: The `list` ARIA role is redundant but | ||
* Safari+VoiceOver won't announce the list otherwise. | ||
*/ | ||
/* eslint-disable jsx-a11y/no-redundant-roles */ | ||
<ul role="list" className="block-editor-block-types-list"> | ||
<Composite | ||
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. Do you think we should expose |
||
as="ul" | ||
role="listbox" | ||
{ ...composite } | ||
className="block-editor-block-types-list" | ||
aria-label={ label } | ||
// This ensures the composite state refreshes when the list order changes. | ||
key={ orderId } | ||
> | ||
{ normalizedItems.map( ( item ) => { | ||
return ( | ||
<InserterListItem | ||
|
@@ -40,11 +59,12 @@ function BlockTypesList( { | |
onBlur={ () => onHover( null ) } | ||
isDisabled={ item.isDisabled } | ||
title={ item.title } | ||
composite={ composite } | ||
youknowriad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
); | ||
} ) } | ||
{ children } | ||
</ul> | ||
</Composite> | ||
/* eslint-enable jsx-a11y/no-redundant-roles */ | ||
); | ||
} | ||
|
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.
It adds nearly 10kB to the module.
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.
yes, I was wondering about that. the solution could be to make it part of the
@wordpress/components
API but then it becomes something we need to ensure BC for. Always a struggle to decide what's best in these situations.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.
Let's improve the experience first and see how the performance might get improved later then.
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 hoping we can balance these kbits loss by refactoring some of our components to rely on reakit like NavigableToolbar/NavigableContainer...
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.
Yes, it's essentially what
Composite
does 👍