Skip to content

Commit b4fb511

Browse files
mpiotrowiczscottgonzalez
authored andcommitted
Tabs: Work around bad Safari/VoiceOver heuristics
Move disabled tab click handlers from the container to the tablist to prevent panel contents from being announced as clickable. Fixes #10098 Closes jquerygh-1261
1 parent 98583a6 commit b4fb511

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

ui/tabs.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,7 @@ return $.widget( "ui.tabs", {
7575

7676
this.element
7777
.addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" )
78-
.toggleClass( "ui-tabs-collapsible", options.collapsible )
79-
// Prevent users from focusing disabled tabs via click
80-
.delegate( ".ui-tabs-nav > li", "mousedown" + this.eventNamespace, function( event ) {
81-
if ( $( this ).is( ".ui-state-disabled" ) ) {
82-
event.preventDefault();
83-
}
84-
})
85-
// support: IE <9
86-
// Preventing the default action in mousedown doesn't prevent IE
87-
// from focusing the element, so if the anchor gets focused, blur.
88-
// We don't have to worry about focusing the previously focused
89-
// element since clicking on a non-focusable element should focus
90-
// the body anyway.
91-
.delegate( ".ui-tabs-anchor", "focus" + this.eventNamespace, function() {
92-
if ( $( this ).closest( "li" ).is( ".ui-state-disabled" ) ) {
93-
this.blur();
94-
}
95-
});
78+
.toggleClass( "ui-tabs-collapsible", options.collapsible );
9679

9780
this._processTabs();
9881
options.active = this._initialActive();
@@ -393,7 +376,26 @@ return $.widget( "ui.tabs", {
393376

394377
this.tablist = this._getList()
395378
.addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" )
396-
.attr( "role", "tablist" );
379+
.attr( "role", "tablist" )
380+
381+
// Prevent users from focusing disabled tabs via click
382+
.delegate( "> li", "mousedown" + this.eventNamespace, function( event ) {
383+
if ( $( this ).is( ".ui-state-disabled" ) ) {
384+
event.preventDefault();
385+
}
386+
})
387+
388+
// support: IE <9
389+
// Preventing the default action in mousedown doesn't prevent IE
390+
// from focusing the element, so if the anchor gets focused, blur.
391+
// We don't have to worry about focusing the previously focused
392+
// element since clicking on a non-focusable element should focus
393+
// the body anyway.
394+
.delegate( ".ui-tabs-anchor", "focus" + this.eventNamespace, function() {
395+
if ( $( this ).closest( "li" ).is( ".ui-state-disabled" ) ) {
396+
this.blur();
397+
}
398+
});
397399

398400
this.tabs = this.tablist.find( "> li:has(a[href])" )
399401
.addClass( "ui-state-default ui-corner-top" )
@@ -711,6 +713,8 @@ return $.widget( "ui.tabs", {
711713
.removeAttr( "tabIndex" )
712714
.removeUniqueId();
713715

716+
this.tablist.unbind( this.eventNamespace );
717+
714718
this.tabs.add( this.panels ).each(function() {
715719
if ( $.data( this, "ui-tabs-destroy" ) ) {
716720
$( this ).remove();

0 commit comments

Comments
 (0)