-
-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add an isDisabled function to identify whether elements are disabled or not #919
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
Merged
eps1lon
merged 6 commits into
eps1lon:main
from
MatanBobi:features/add-elements-supporting-disabled-attribute
May 7, 2023
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d75689d
feat: add a list of elements supporting disabled attribute
MatanBobi 6196733
add missing changeset
MatanBobi c48f242
failing lint
MatanBobi ad0fd04
export a function instead of an array
MatanBobi e051f9c
fix tests
MatanBobi 38c8dbe
Update sources/__tests__/is-disabled.js
eps1lon 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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"dom-accessibility-api": minor | ||
--- | ||
|
||
add an `isDisabled` function to check if elements are disabled or not |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isDisabled } from "../is-disabled"; | ||
import { cleanup, renderIntoDocument } from "./helpers/test-utils"; | ||
|
||
describe("isInaccessible", () => { | ||
afterEach(cleanup); | ||
test.each([ | ||
["<button data-test />", false], | ||
['<button data-test aria-disabled="true" />', true], | ||
['<button data-test disabled="true" />', true], | ||
["<button data-test disabled />", true], | ||
['<button data-test aria-disabled="false" />', false], | ||
["<div data-test disabled />", false], | ||
])("markup #%#", (markup, expectedIsDisabled) => { | ||
const container = renderIntoDocument(markup); | ||
expect(container).not.toBe(null); | ||
|
||
const testNode = container.querySelector("[data-test]"); | ||
expect(isDisabled(testNode)).toBe(expectedIsDisabled); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getLocalName } from "./getRole"; | ||
|
||
const elementsSupportingDisabledAttribute = new Set([ | ||
"button", | ||
"fieldset", | ||
"input", | ||
"optgroup", | ||
"option", | ||
"select", | ||
"textarea", | ||
]); | ||
|
||
/** | ||
* Check if an element is disabled | ||
* https://www.w3.org/TR/html-aam-1.0/#html-attribute-state-and-property-mappings | ||
* https://www.w3.org/TR/wai-aria-1.1/#aria-disabled | ||
* | ||
* @param element | ||
* @returns {boolean} true if disabled, otherwise false | ||
*/ | ||
export function isDisabled(element: Element): boolean { | ||
const localName = getLocalName(element); | ||
return elementsSupportingDisabledAttribute.has(localName) && | ||
element.hasAttribute("disabled") | ||
? true | ||
: element.getAttribute("aria-disabled") === "true"; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.