Skip to content

Commit

Permalink
Update to use a11y script module package in Core. (#65539)
Browse files Browse the repository at this point in the history
Update the interactivity-router package to use the @wordpress/a11y module for its aria-live regions.

This was behind a Gutenberg-only flag. Since the a11y module is landing in Core in 6.7, the flag can be removed to always use the a11y module.

See WordPress/wordpress-develop#7304.
  • Loading branch information
sirreal authored and gutenbergplugin committed Sep 26, 2024
1 parent 87b1251 commit 20ae57d
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions packages/interactivity-router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ interface Store {
navigation: {
hasStarted: boolean;
hasFinished: boolean;
message: string;
texts?: {
loading?: string;
loaded?: string;
};
};
};
actions: {
Expand All @@ -240,7 +235,6 @@ export const { state, actions } = store< Store >( 'core/router', {
navigation: {
hasStarted: false,
hasFinished: false,
message: '',
},
},
actions: {
Expand Down Expand Up @@ -403,30 +397,28 @@ function a11ySpeak( messageKey: keyof typeof navigationTexts ) {
} catch {}
} else {
// Fallback to localized strings from Interactivity API state.
// @todo This block is for Core < 6.7.0. Remove when support is dropped.

// @ts-expect-error
if ( state.navigation.texts?.loading ) {
// @ts-expect-error
navigationTexts.loading = state.navigation.texts.loading;
}
// @ts-expect-error
if ( state.navigation.texts?.loaded ) {
// @ts-expect-error
navigationTexts.loaded = state.navigation.texts.loaded;
}
}
}

const message = navigationTexts[ messageKey ];

if ( globalThis.IS_GUTENBERG_PLUGIN ) {
import( '@wordpress/a11y' ).then(
( { speak } ) => speak( message ),
// Ignore failures to load the a11y module.
() => {}
);
} 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' : '' );
}
import( '@wordpress/a11y' ).then(
( { speak } ) => speak( message ),
// Ignore failures to load the a11y module.
() => {}
);
}

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

0 comments on commit 20ae57d

Please sign in to comment.