-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aria-required-attr): allow aria-valuenow to pass on elements with…
… value (#1579) * fix(aria-required-attr): allow aria-valuenow to pass on elements with value * allow empty string values to pass * add new form functions to identify elements with value * reset file * fix IE11 * move hasAttribute check outside isAriaRange
- Loading branch information
Showing
18 changed files
with
415 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Namespace for forms-related utilities. | ||
* @namespace commons.forms | ||
* @memberof axe | ||
*/ | ||
|
||
var forms = {}; | ||
commons.forms = forms; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* global forms */ | ||
|
||
/** | ||
* Determines if an element is an aria combobox element | ||
* @method isAriaCombobox | ||
* @memberof axe.commons.forms | ||
* @param {Element} node Node to determine if aria combobox | ||
* @returns {Bool} | ||
*/ | ||
forms.isAriaCombobox = function(node) { | ||
const role = axe.commons.aria.getRole(node, { noImplicit: true }); | ||
return role === 'combobox'; | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* global forms */ | ||
|
||
/** | ||
* Determines if an element is an aria listbox element | ||
* @method isAriaListbox | ||
* @memberof axe.commons.forms | ||
* @param {Element} node Node to determine if aria listbox | ||
* @returns {Bool} | ||
*/ | ||
forms.isAriaListbox = function(node) { | ||
const role = axe.commons.aria.getRole(node, { noImplicit: true }); | ||
return role === 'listbox'; | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* global forms */ | ||
const rangeRoles = ['progressbar', 'scrollbar', 'slider', 'spinbutton']; | ||
|
||
/** | ||
* Determines if an element is an aria range element | ||
* @method isAriaRange | ||
* @memberof axe.commons.forms | ||
* @param {Element} node Node to determine if aria range | ||
* @returns {Bool} | ||
*/ | ||
forms.isAriaRange = function(node) { | ||
const role = axe.commons.aria.getRole(node, { noImplicit: true }); | ||
return rangeRoles.includes(role); | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* global forms */ | ||
|
||
/** | ||
* Determines if an element is an aria textbox element | ||
* @method isAriaTextbox | ||
* @memberof axe.commons.forms | ||
* @param {Element} node Node to determine if aria textbox | ||
* @returns {Bool} | ||
*/ | ||
forms.isAriaTextbox = function(node) { | ||
const role = axe.commons.aria.getRole(node, { noImplicit: true }); | ||
return role === 'textbox'; | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* global forms */ | ||
|
||
/** | ||
* Determines if an element is a native select element | ||
* @method isNativeSelect | ||
* @memberof axe.commons.forms | ||
* @param {Element} node Node to determine if select | ||
* @returns {Bool} | ||
*/ | ||
forms.isNativeSelect = function(node) { | ||
const nodeName = node.nodeName.toUpperCase(); | ||
return nodeName === 'SELECT'; | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* global forms */ | ||
const nonTextInputTypes = [ | ||
'button', | ||
'checkbox', | ||
'color', | ||
'file', | ||
'hidden', | ||
'image', | ||
'password', | ||
'radio', | ||
'reset', | ||
'submit' | ||
]; | ||
|
||
/** | ||
* Determines if an element is a native textbox element | ||
* @method isNativeTextbox | ||
* @memberof axe.commons.forms | ||
* @param {Element} node Node to determine if textbox | ||
* @returns {Bool} | ||
*/ | ||
forms.isNativeTextbox = function(node) { | ||
const nodeName = node.nodeName.toUpperCase(); | ||
return ( | ||
nodeName === 'TEXTAREA' || | ||
(nodeName === 'INPUT' && !nonTextInputTypes.includes(node.type)) | ||
); | ||
}; |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe('forms.isAriaCombobox', function() { | ||
'use strict'; | ||
var isAriaCombobox = axe.commons.forms.isAriaCombobox; | ||
|
||
it('returns true for an element with role=combobox', function() { | ||
var node = document.createElement('div'); | ||
node.setAttribute('role', 'combobox'); | ||
assert.isTrue(isAriaCombobox(node)); | ||
}); | ||
|
||
it('returns false for elements without role', function() { | ||
var node = document.createElement('div'); | ||
assert.isFalse(isAriaCombobox(node)); | ||
}); | ||
|
||
it('returns false for elements with incorrect role', function() { | ||
var node = document.createElement('div'); | ||
node.setAttribute('role', 'main'); | ||
assert.isFalse(isAriaCombobox(node)); | ||
}); | ||
}); |
Oops, something went wrong.