Skip to content

Commit

Permalink
Create a11y module
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Sep 5, 2024
1 parent 287ad44 commit 20c00aa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"wp-module": "build-module/module/index.js",
"react-native": "src/index",
"types": "build-types",
"dependencies": {
Expand Down
25 changes: 25 additions & 0 deletions packages/a11y/src/module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Internal dependencies
*/
import { makeSetupFunction } from '../shared/index';
export { speak } from '../shared/index';

// Without an i18n script-module, "Notifications" (the only localized text used in this module)
// will be trasnlated on the server and provided as script-module data.
let notificationsText = 'Notifications';
try {
const textContent = document.getElementById(
'wp-script-module-data-@wordpress/a11y'
)?.textContent;
if ( textContent ) {
const parsed = JSON.parse( textContent );
notificationsText = parsed?.i18n?.Notifications ?? notificationsText;
}
} catch {}

/**
* Create the live regions.
*/
export const setup = makeSetupFunction( notificationsText );

setup();
2 changes: 2 additions & 0 deletions tools/webpack/script-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module.exports = {
...baseConfig,
name: 'script-modules',
entry: {
a11y: './packages/a11y',

interactivity: './packages/interactivity',
'interactivity-debug': './packages/interactivity/src/debug',
'interactivity-router': './packages/interactivity-router',
Expand Down

0 comments on commit 20c00aa

Please sign in to comment.