Skip to content

Commit

Permalink
Append a no-break space to repeated messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Apr 18, 2017
1 parent a968fff commit 969f3bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions a11y-speak.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var containerPolite, containerAssertive;
var containerPolite, containerAssertive, previousMessage = "";

/**
* Build the live regions markup.
Expand All @@ -14,7 +14,7 @@ var addContainer = function( ariaLive ) {
container.id = "a11y-speak-" + ariaLive;
container.className = "a11y-speak-region";

var screenReaderTextStyle = "clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden;";
var screenReaderTextStyle = "clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden; word-wrap: normal;";
container.setAttribute( "style", screenReaderTextStyle );

container.setAttribute( "aria-live", ariaLive );
Expand Down Expand Up @@ -85,6 +85,12 @@ var A11ySpeak = function( message, ariaLive ) {
*/
message = message.replace( /<[^<>]+>/g, " " );

if ( previousMessage === message ) {
message = message + "\u00A0";
}

previousMessage = message;

if ( containerAssertive && "assertive" === ariaLive ) {
containerAssertive.textContent = message;
} else if ( containerPolite ) {
Expand Down
2 changes: 1 addition & 1 deletion a11y-speak.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 969f3bc

Please sign in to comment.