Skip to content

Commit

Permalink
Navigation block: Add notice on reduced accessibility (#52251)
Browse files Browse the repository at this point in the history
* Add notice on reduced accessibility submenu options

* Make notice assertive

* Don't read the notice on the initial render

* Speak full message and remove assertive
  • Loading branch information
luisherranz authored Jul 10, 2023
1 parent 1f82e3f commit 9baa061
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
Button,
Spinner,
Notice,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';
Expand Down Expand Up @@ -485,6 +486,21 @@ function Navigation( {
{ open: overlayMenuPreview }
);

const submenuAccessibilityNotice =
! showSubmenuIcon && ! openSubmenusOnClick
? __(
'The current menu options offer reduced accessibility for users and are not recommended. Enabling either "Open on Click" or "Show arrow" offers enhanced accessibility by allowing keyboard users to browse submenus selectively.'
)
: '';

const isFirstRender = useRef( true ); // Don't speak on first render.
useEffect( () => {
if ( ! isFirstRender.current && submenuAccessibilityNotice ) {
speak( submenuAccessibilityNotice );
}
isFirstRender.current = false;
}, [ submenuAccessibilityNotice ] );

const colorGradientSettings = useMultipleOriginColorsAndGradients();
const stylingInspectorControls = (
<>
Expand Down Expand Up @@ -578,6 +594,18 @@ function Navigation( {
disabled={ attributes.openSubmenusOnClick }
label={ __( 'Show arrow' ) }
/>

{ submenuAccessibilityNotice && (
<div>
<Notice
spokenMessage={ null }
status="warning"
isDismissible={ false }
>
{ submenuAccessibilityNotice }
</Notice>
</div>
) }
</>
) }
</PanelBody>
Expand Down

1 comment on commit 9baa061

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 9baa061.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5510115260
📝 Reported issues:

Please sign in to comment.