Skip to content

Commit

Permalink
Only use a11y module in GUTENBERG_PLUGIN
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Sep 6, 2024
1 parent 8b14d3a commit a39c437
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/interactivity-router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,19 @@ export const { state, actions } = store( 'core/router', {
* @param ariaLive The politeness level for aria-live; default: 'polite'.
*/
function a11yAnnounce( message: string, ariaLive?: 'polite' | 'assertive' ) {
import( '@wordpress/a11y' ).then(
( { speak } ) => speak( message, ariaLive ),
// Silence errors.
() => undefined
);
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
import( '@wordpress/a11y' ).then(
( { speak } ) => speak( message, ariaLive ),
// Silence errors.
() => undefined
);
} else {
state.navigation.message =
// Announce that the page has been loaded. If the message is the
// same, we use a no-break space similar to the @wordpress/a11y
// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
message + ( state.navigation.message === message ? '\u00A0' : '' );
}
}

// Add click and prefetch to all links.
Expand Down

0 comments on commit a39c437

Please sign in to comment.