-
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
Closed
Closed
Null attributes #1516
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cd8698c
Core: Fix `:focusable` and `:tabbable` with jQuery git
scottgonzalez 6d633a3
Tests: Update `domEqual()` to work with jQuery git
scottgonzalez b211d97
Dialog: Properly handle empty title with jQuery git
scottgonzalez c0f6b06
Spinner: Properly handle empty attributes in create with jQuery git
scottgonzalez abaee2a
Tests: Handle jQuery git returning `null` for empty attributes
scottgonzalez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Core: Fix
:focusable
and :tabbable
with jQuery git
jQuery now returns `null` for empty attributes instead of `undefined`
- Loading branch information
commit cd8698c9c2307144adc1e1b2e280681dc7fc95e4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
}, | ||
|
||
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. |
||
} | ||
} ); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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
!isNaN( parseInt( $.attr( element, "tabindex" ), 10 ) )
. See also: https://github.com/jquery/jquery/blob/7b111310977a30d02a8260a7ed6c9c437bb1b0a5/src/attributes/prop.js#L64-L79There 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.
"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 comment
The 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 comment
The 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
tabindex="bananas"
and it resulted in our selectors finding incorrect elements, we'd close it the same as if they filed a bug about our widgets not working properly when they used the sameid
on multiple elements :-)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 used to actually test for invalid values: f80d9eb#diff-47738b779c41035dcc321cc78634c6a5R87, but we dropped those tests four years ago.