Skip to content

Commit

Permalink
Merge pull request #42 from WordPress/fix/38-speak-region-overflow
Browse files Browse the repository at this point in the history
a11y: Use screen-reader-text styles for speak container
  • Loading branch information
omarreiss authored Nov 28, 2017
2 parents 4ad0565 + 49e57d9 commit 8e6bfcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions packages/a11y/src/addContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ const addContainer = function( ariaLive ) {
container.id = 'a11y-speak-' + ariaLive;
container.className = 'a11y-speak-region';

let screenReaderTextStyle = 'clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden; word-wrap: normal;';
container.setAttribute( 'style', screenReaderTextStyle );
container.setAttribute( 'style', (
'position: absolute;' +
'margin: -1px;' +
'padding: 0;' +
'height: 1px;' +
'width: 1px;' +
'overflow: hidden;' +
'clip: rect( 0 0 0 0 );' +
'border: 0;' +
'word-wrap: normal !important;'
) );
container.setAttribute( 'aria-live', ariaLive );
container.setAttribute( 'aria-relevant', 'additions text' );
container.setAttribute( 'aria-atomic', 'true' );
Expand Down
6 changes: 3 additions & 3 deletions packages/a11y/src/test/addContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe( 'addContainer', () => {
expect( container ).not.toBe( null );
expect( container.className ).toBe( 'a11y-speak-region' );
expect( container.id ).toBe( 'a11y-speak-polite' );
expect( container.getAttribute( 'style' ) ).toBe( 'clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden; word-wrap: normal;' );
expect( container.getAttribute( 'style' ) ).not.toBeNull();
expect( container.getAttribute( 'aria-live' ) ).toBe( 'polite' );
expect( container.getAttribute( 'aria-relevant' ) ).toBe( 'additions text' );
expect( container.getAttribute( 'aria-atomic' ) ).toBe( 'true' );
Expand All @@ -22,7 +22,7 @@ describe( 'addContainer', () => {
expect( container ).not.toBe( null );
expect( container.className ).toBe( 'a11y-speak-region' );
expect( container.id ).toBe( 'a11y-speak-assertive' );
expect( container.getAttribute( 'style' ) ).toBe( 'clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden; word-wrap: normal;' );
expect( container.getAttribute( 'style' ) ).not.toBeNull();
expect( container.getAttribute( 'aria-live' ) ).toBe( 'assertive' );
expect( container.getAttribute( 'aria-relevant' ) ).toBe( 'additions text' );
expect( container.getAttribute( 'aria-atomic' ) ).toBe( 'true' );
Expand All @@ -36,7 +36,7 @@ describe( 'addContainer', () => {
expect( container ).not.toBe( null );
expect( container.className ).toBe( 'a11y-speak-region' );
expect( container.id ).toBe( 'a11y-speak-polite' );
expect( container.getAttribute( 'style' ) ).toBe( 'clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden; word-wrap: normal;' );
expect( container.getAttribute( 'style' ) ).not.toBeNull();
expect( container.getAttribute( 'aria-live' ) ).toBe( 'polite' );
expect( container.getAttribute( 'aria-relevant' ) ).toBe( 'additions text' );
expect( container.getAttribute( 'aria-atomic' ) ).toBe( 'true' );
Expand Down

0 comments on commit 8e6bfcf

Please sign in to comment.