Skip to content
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

Fix Block Navigation Settings Menu keyboard navigation in Navigation Menus page #22885

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/block-editor/src/components/block-navigation/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function BlockNavigationBlock( {
className="block-editor-block-navigation-block__contents-cell"
colSpan={ hasRenderedMovers ? undefined : 3 }
>
{ ( props ) => (
{ ( { ref, tabIndex, onFocus } ) => (
<div className="block-editor-block-navigation-block__contents-container">
<DescenderLines
level={ level }
Expand All @@ -87,28 +87,34 @@ export default function BlockNavigationBlock( {
position={ position }
siblingCount={ siblingCount }
level={ level }
{ ...props }
ref={ ref }
tabIndex={ tabIndex }
onFocus={ onFocus }
/>
</div>
) }
</TreeGridCell>
{ hasRenderedMovers && (
<>
<TreeGridCell className={ moverCellClassName }>
{ ( props ) => (
{ ( { ref, tabIndex, onFocus } ) => (
<BlockMoverUpButton
__experimentalOrientation="vertical"
clientIds={ [ clientId ] }
{ ...props }
ref={ ref }
tabIndex={ tabIndex }
onFocus={ onFocus }
/>
) }
</TreeGridCell>
<TreeGridCell className={ moverCellClassName }>
{ ( props ) => (
{ ( { ref, tabIndex, onFocus } ) => (
<BlockMoverDownButton
__experimentalOrientation="vertical"
clientIds={ [ clientId ] }
{ ...props }
ref={ ref }
tabIndex={ tabIndex }
onFocus={ onFocus }
/>
) }
</TreeGridCell>
Expand All @@ -119,11 +125,16 @@ export default function BlockNavigationBlock( {
<TreeGridCell
className={ blockNavigationBlockSettingsClassName }
>
{ ( props ) => (
{ ( { ref, tabIndex, onFocus } ) => (
<BlockSettingsDropdown
clientIds={ [ clientId ] }
icon={ moreVertical }
{ ...props }
toggleProps={ {
ref,
tabIndex,
onFocus,
} }
disableOpenOnArrowDown
/>
) }
</TreeGridCell>
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/dropdown-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ Use this object to modify props available for the `NavigableMenu` component that

- Type: `Object`
- Required: No

#### disableOpenOnArrowDown

In some contexts, the arrow down key used to open the dropdown menu might need to be disabled—for example when that key is used to perform another action.

- Type: `Object`
- Required: No
- Default: `false`
5 changes: 5 additions & 0 deletions packages/components/src/dropdown-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function DropdownMenu( {
popoverProps,
toggleProps,
menuProps,
disableOpenOnArrowDown = false,
// The following props exist for backward compatibility.
menuLabel,
position,
Expand Down Expand Up @@ -87,6 +88,10 @@ function DropdownMenu( {
popoverProps={ mergedPopoverProps }
renderToggle={ ( { isOpen, onToggle } ) => {
const openOnArrowDown = ( event ) => {
if ( disableOpenOnArrowDown ) {
return;
}

if ( ! isOpen && event.keyCode === DOWN ) {
event.preventDefault();
event.stopPropagation();
Expand Down