-
Notifications
You must be signed in to change notification settings - Fork 779
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
refactor(#4632): correct tabindex parsing logic #4637
base: develop
Are you sure you want to change the base?
refactor(#4632): correct tabindex parsing logic #4637
Conversation
Ensures tabindex is correctly parsed as an integer using regex instead of parseInt to comply with HTML standards. Related to dequelabs#4632
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 is a good start, but I think we can do a little better. Going over the code base, it looks like axe has an awful lot of places where it's parsing tabindex. I think it would be better if we put the code for this in one place. Normally we'd do this in a commons
function, but because one of the places is in core, we'll need to do this in core/utils
. So how about this:
In lib/core/utils/
create a file parse-tabindex.js
with a parseTabindex
function that accepts either a string or null. And which returns an integer if the string is a valid tabindex value, or null if not valid or if the value is null. This would need tests in a new test/core/utils/parse-tabindex.js
.
This function could then be used in the following files, instead of the current ad-hoc methods:
lib/checks/keyboard/focusable-no-name-evaluate.js
lib/checks/keyboard/no-focusable-content-evaluate.js
lib/checks/keyboard/tabindex-evaluate.js
lib/commons/dom/get-tabbable-elements.js
lib/commons/dom/inserted-into-focus-order.js
lib/commons/dom/is-focusable.js
lib/commons/dom/is-in-tab-order.js
lib/core/base/context/create-frame-context.js
lib/rules/autocomplete-matches.js
lib/rules/no-negative-tabindex-matches.js
Add parseTabindex method in lib/core/utils and reused it in multiple places across the codebase Related to dequelabs#4632
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 is looking great! The change required a few additional updates, this is looking really good.
Resolving pull request comments Related to dequelabs#4637
Ensures tabindex is correctly parsed as an integer using regex instead of parseInt to comply with HTML standards.
Related to #4632