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 3 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,10 @@
export default function AccessibleDescription( { id, content } ) {
return (
<div
id={ id }
className="wp-block-navigation__description screen-reader-text"
getdave marked this conversation as resolved.
Show resolved Hide resolved
>
{ content }
getdave marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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 } content={ description } />;
}
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 }
content={ __( 'Unsaved Navigation Menu.' ) }
/>
<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