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

Add accessible description of current Navigation block state #53469

Merged
merged 6 commits into from
Aug 11, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* WordPress dependencies
*/
import { VisuallyHidden } from '@wordpress/components';

export default function AccessibleDescription( { id, children } ) {
return (
<VisuallyHidden>
<div id={ id } className="wp-block-navigation__description">
{ children }
</div>
</VisuallyHidden>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import AccessibleDescription from './accessible-description';

export default function AccessibleMenuDescription( { id } ) {
const [ menuTitle ] = useEntityProp( 'postType', 'wp_navigation', 'title' );
/* translators: %s: Title of a Navigation Menu post. */
const description = sprintf( __( `Navigation menu: "%s"` ), menuTitle );

return (
<AccessibleDescription id={ id }>{ description }</AccessibleDescription>
);
}
27 changes: 25 additions & 2 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import { detectColors } from './utils';
import ManageMenusButton from './manage-menus-button';
import MenuInspectorControls from './menu-inspector-controls';
import DeletedNavigationWarning from './deleted-navigation-warning';
import AccessibleDescription from './accessible-description';
import AccessibleMenuDescription from './accessible-menu-description';
import { unlock } from '../../lock-unlock';

function Navigation( {
Expand Down Expand Up @@ -665,12 +667,23 @@ function Navigation( {
</>
);

const accessibleDescriptionId = `${ clientId }-desc`;

const isManageMenusButtonDisabled =
! hasManagePermissions || ! hasResolvedNavigationMenus;

if ( hasUnsavedBlocks && ! isCreatingNavigationMenu ) {
return (
<TagName { ...blockProps }>
<TagName
{ ...blockProps }
aria-describedby={
! isPlaceholder ? accessibleDescriptionId : undefined
}
>
<AccessibleDescription id={ accessibleDescriptionId }>
{ __( 'Unsaved Navigation Menu.' ) }
</AccessibleDescription>

<MenuInspectorControls
clientId={ clientId }
createNavigationMenuIsSuccess={
Expand Down Expand Up @@ -836,7 +849,17 @@ function Navigation( {
) }

{ ! isLoading && (
<TagName { ...blockProps }>
<TagName
{ ...blockProps }
aria-describedby={
! isPlaceholder
? accessibleDescriptionId
: undefined
}
>
<AccessibleMenuDescription
id={ accessibleDescriptionId }
/>
<ResponsiveWrapper
id={ clientId }
onToggle={ setResponsiveMenuVisibility }
Expand Down
Loading