Skip to content

Commit

Permalink
fix issue 2002 by rewriting live region after delay
Browse files Browse the repository at this point in the history
  • Loading branch information
bbenjamin committed Dec 8, 2021
1 parent e90096e commit db3b6ef
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ui/widgets/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ $.widget( "ui.autocomplete", {

requestIndex: 0,
pending: 0,
liveRegionTimer: null,

_create: function() {

Expand Down Expand Up @@ -267,8 +268,10 @@ $.widget( "ui.autocomplete", {
// Announce the value in the liveRegion
label = ui.item.attr( "aria-label" ) || item.value;
if ( label && String.prototype.trim.call( label ).length ) {
this.liveRegion.children().hide();
$( "<div>" ).text( label ).appendTo( this.liveRegion );
clearTimeout( this.liveRegionTimer );
this.liveRegionTimer = setTimeout(() => {
this.liveRegion.html($( "<div>" ).text( label ));
}, 400);
}
},
menuselect: function( event, ui ) {
Expand Down Expand Up @@ -663,8 +666,10 @@ $.widget( "ui.autocomplete", $.ui.autocomplete, {
} else {
message = this.options.messages.noResults;
}
this.liveRegion.children().hide();
$( "<div>" ).text( message ).appendTo( this.liveRegion );
clearTimeout( this.liveRegionTimer );
this.liveRegionTimer = setTimeout(() => {
this.liveRegion.html($( "<div>" ).text( message ));
}, 400);
}
} );

Expand Down

0 comments on commit db3b6ef

Please sign in to comment.