Skip to content

Commit b3e81ee

Browse files
authored
A11y: Add types (WordPress#19096)
1 parent 1a9094b commit b3e81ee

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/a11y/src/addContainer.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @param {string} ariaLive Optional. Value for the 'aria-live' attribute, default 'polite'.
55
*
6-
* @return {Object} $container The ARIA live region jQuery object.
6+
* @return {HTMLDivElement} The ARIA live region HTML element.
77
*/
88
const addContainer = function( ariaLive ) {
99
ariaLive = ariaLive || 'polite';
@@ -29,7 +29,11 @@ const addContainer = function( ariaLive ) {
2929
container.setAttribute( 'aria-relevant', 'additions text' );
3030
container.setAttribute( 'aria-atomic', 'true' );
3131

32-
document.querySelector( 'body' ).appendChild( container );
32+
const body = document.querySelector( 'body' );
33+
if ( body ) {
34+
body.appendChild( container );
35+
}
36+
3337
return container;
3438
};
3539

packages/a11y/src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import filterMessage from './filterMessage';
1414
* Create the live regions.
1515
*/
1616
export const setup = function() {
17-
let containerPolite = document.getElementById( 'a11y-speak-polite' );
18-
let containerAssertive = document.getElementById( 'a11y-speak-assertive' );
17+
const containerPolite = document.getElementById( 'a11y-speak-polite' );
18+
const containerAssertive = document.getElementById( 'a11y-speak-assertive' );
1919

2020
if ( containerPolite === null ) {
21-
containerPolite = addContainer( 'polite' );
21+
addContainer( 'polite' );
2222
}
2323
if ( containerAssertive === null ) {
24-
containerAssertive = addContainer( 'assertive' );
24+
addContainer( 'assertive' );
2525
}
2626
};
2727

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
3232
},
3333
"include": [
34+
"./packages/a11y/**/*.js",
3435
"./packages/blob/**/*.js",
3536
"./packages/dom-ready/**/*.js",
3637
"./packages/i18n/**/*.js",

0 commit comments

Comments
 (0)