Skip to content

Commit

Permalink
Use composite.unstable_sort and update html structure
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohaz committed Jul 15, 2020
1 parent c682202 commit 506de60
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/block-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"react-autosize-textarea": "^3.0.2",
"react-spring": "^8.0.19",
"react-transition-group": "^2.9.0",
"reakit": "^1.1.0",
"reakit": "1.1.0",
"redux-multi": "^0.1.12",
"refx": "^3.0.0",
"rememo": "^3.0.0",
Expand Down
11 changes: 7 additions & 4 deletions packages/block-editor/src/components/block-types-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Composite, useCompositeState } from 'reakit';
* WordPress dependencies
*/
import { getBlockMenuDefaultClassName } from '@wordpress/blocks';
import { useEffect } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -28,20 +29,22 @@ function BlockTypesList( {
''
);

// This ensures the composite state refreshes when the list order changes.
useEffect( () => {
composite.unstable_sort();
}, [ composite.unstable_sort, orderId ] );

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 */
<Composite
as="ul"
role="listbox"
{ ...composite }
role="listbox"
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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ function InserterListItem( {
: {};

return (
<li className="block-editor-block-types-list__list-item" role="option">
<div className="block-editor-block-types-list__list-item">
<CompositeItem
role="option"
as={ Button }
{ ...composite }
className={ classnames(
Expand All @@ -56,7 +57,7 @@ function InserterListItem( {
{ title }
</span>
</CompositeItem>
</li>
</div>
);
}

Expand Down

0 comments on commit 506de60

Please sign in to comment.