-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Null attributes #1516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null attributes #1516
Changes from all commits
cd8698c
6d633a3
b211d97
c0f6b06
abaee2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,7 @@ $.fn.extend( { | |
} ); | ||
|
||
// selectors | ||
function focusable( element, isTabIndexNotNaN ) { | ||
function focusable( element, hasTabindex ) { | ||
var map, mapName, img, | ||
nodeName = element.nodeName.toLowerCase(); | ||
if ( "area" === nodeName ) { | ||
|
@@ -131,8 +131,8 @@ function focusable( element, isTabIndexNotNaN ) { | |
return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ? | ||
!element.disabled : | ||
"a" === nodeName ? | ||
element.href || isTabIndexNotNaN : | ||
isTabIndexNotNaN ) && | ||
element.href || hasTabindex : | ||
hasTabindex ) && | ||
// the element and all of its ancestors must be visible | ||
visible( element ); | ||
} | ||
|
@@ -157,13 +157,13 @@ $.extend( $.expr[ ":" ], { | |
}, | ||
|
||
focusable: function( element ) { | ||
return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) ); | ||
return focusable( element, $.attr( element, "tabindex" ) != null ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code isn't equivalent, and it looks like even the old version has bugs for some unusual tabindex values (e.g., "0xFF", "Infinity"). Reviewing https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute and reviewing browser behavior, I think you want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "0xFF" and "Infinity" aren't valid values. We've decided not to account for such markup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the presence of a "tabindex" attribute is all that matters, independent of its value? In that case, 👍. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For our intents, yes. We assume that if the attribute exists, it contains a valid value. If someone were to file a bug saying that they did something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We used to actually test for invalid values: f80d9eb#diff-47738b779c41035dcc321cc78634c6a5R87, but we dropped those tests four years ago. |
||
}, | ||
|
||
tabbable: function( element ) { | ||
var tabIndex = $.attr( element, "tabindex" ), | ||
isTabIndexNaN = isNaN( tabIndex ); | ||
return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN ); | ||
hasTabindex = tabIndex != null; | ||
return ( !hasTabindex || tabIndex >= 0 ) && focusable( element, hasTabindex ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same concerns here. |
||
} | ||
} ); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,9 @@ $.widget( "ui.dialog", { | |
index: this.element.parent().children().index( this.element ) | ||
}; | ||
this.originalTitle = this.element.attr( "title" ); | ||
this.options.title = this.options.title || this.originalTitle; | ||
if ( this.options.title == null && this.originalTitle != null ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks like a ride-along bug fix for empty-string |
||
this.options.title = this.originalTitle; | ||
} | ||
|
||
this._createWrapper(); | ||
|
||
|
@@ -433,10 +435,11 @@ $.widget( "ui.dialog", { | |
}, | ||
|
||
_title: function( title ) { | ||
if ( !this.options.title ) { | ||
if ( this.options.title ) { | ||
title.text( this.options.title ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if core back out the change, this change should stay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say the same of every change here. If nothing else, specifically counting on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's legitimate. I'll go ahead and land this. |
||
} else { | ||
title.html( " " ); | ||
} | ||
title.text( this.options.title ); | ||
}, | ||
|
||
_createButtonPane: function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This strict comparison was fine as-is;
.prop
lacks the DOM semantics that urged us to try changing.attr
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And looking at the broader context,
domEqual
might still work if you stopped doing this empty-string normalization altogether and just assigned results from.prop
and.attr
directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do the normalization because of space delimited attributes, the most common one being
class
. The attribute will start outundefined
, but afterelem.addClass( "foo" ).removeClass( "foo" )
, the attribute will be an empty string. We consider this equivalent.For the property check, the aim was just consistency in the logic. I don't think we've ever consider
null
andundefined
to be non-equivalent in our check.