Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Autocomplete: Insert the live region before the input. Fixes #9172 - …

…Autocomplete: .replaceWith() fails to replace.
  • Loading branch information...
commit ff11b69a67e0176c851ff3bdec997c7a75d47a42 1 parent f281ce9
@scottgonzalez scottgonzalez authored
View
10 tests/unit/autocomplete/autocomplete_core.js
@@ -188,4 +188,14 @@ test( "ARIA", function() {
"Live region for multiple values" );
});
+test( ".replaceWith() (#9172)", function() {
+ expect( 1 );
+
+ var element = $( "#autocomplete" ).autocomplete(),
+ replacement = "<div>test</div>",
+ parent = element.parent();
+ element.replaceWith( replacement );
+ equal( parent.html(), replacement );
+});
+
}( jQuery ) );
View
2  ui/jquery.ui.autocomplete.js
@@ -296,7 +296,7 @@ $.widget( "ui.autocomplete", {
"aria-live": "polite"
})
.addClass( "ui-helper-hidden-accessible" )
- .insertAfter( this.element );
+ .insertBefore( this.element );
// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete

2 comments on commit ff11b69

@michalbcz

Why is this works? What is a reason that jQuery#replaceWith is sensitive on position of widget element (before vs after) ?

@scottgonzalez

When .replaceWith() runs, it removes the input element. When that element is removed, the autocomplete widget automatically destroys itself. When the autocomplete widget is destroyed, the live region is removed. When .replaceWith() does the insertion, it needs to have a reference to an element to insert relative to (it could be the next sibling, the previous sibling, or the parent if there are no siblings). We just have to use the position that happens to work with the current implementation. It's unlikely that the position used by .replaceWith() will change in the future.

Please sign in to comment.
Something went wrong with that request. Please try again.