-
x
-
-
-
- x
-
-
+ test('throws when element with aria-disabled attribute is enabled but expected not to be', () => {
+ const {queryByTestId} = render(`
+
+ `)
+ expect(() =>
+ expect(queryByTestId(`aria-div-enabled`)).not.toBeEnabled(),
+ ).toThrowError()
+ })
+
+ test('throws when element with aria-disabled role is not enabled but expected to be', () => {
+ const {queryByTestId} = render(`
+
+ `)
+ expect(() =>
+ expect(queryByTestId(`aria-div-disabled`)).toBeEnabled(),
+ ).toThrowError()
+ })
+
+ test('handles inheritance of the disabled state from a parent with aria-disabled attribute', () => {
+ const {queryByTestId} = render(`
+
+
+ x
+
+
+
+ x
-
x
-
-
x
-
- `)
+
+ x
+
- expect(() => {
- expect(queryByTestId('button-element')).toBeEnabled()
- }).toThrowError()
- expect(queryByTestId('button-element')).not.toBeEnabled()
- expect(() => {
- expect(queryByTestId('textarea-element')).toBeEnabled()
- }).toThrowError()
- expect(() => {
- expect(queryByTestId('input-element')).toBeEnabled()
- }).toThrowError()
+
+
x
+
- expect(() => {
- expect(queryByTestId('fieldset-element')).toBeEnabled()
- }).toThrowError()
- expect(() => {
- expect(queryByTestId('fieldset-child-element')).toBeEnabled()
- }).toThrowError()
+
+
+ x
- expect(queryByTestId('div-element')).toBeEnabled()
- expect(queryByTestId('div-child-element')).toBeEnabled()
+
+
+ x
+
+
+
+
x
+
- expect(() => {
- expect(queryByTestId('nested-form-element')).toBeEnabled()
- }).toThrowError()
- expect(() => {
- expect(queryByTestId('deep-select-element')).toBeEnabled()
- }).toThrowError()
- expect(() => {
- expect(queryByTestId('deep-optgroup-element')).toBeEnabled()
- }).toThrowError()
- expect(() => {
- expect(queryByTestId('deep-option-element')).toBeEnabled()
- }).toThrowError()
+
x
+
+ `)
- expect(queryByTestId('a-element')).toBeEnabled()
- expect(() =>
- expect(queryByTestId('a-element')).not.toBeEnabled(),
- ).toThrowError()
- expect(queryByTestId('deep-a-element')).toBeEnabled()
- expect(() =>
- expect(queryByTestId('deep-a-element')).not.toBeEnabled(),
- ).toThrowError()
+ expect(queryByTestId('fieldset-element')).toBeEnabled()
+ expect(queryByTestId('fieldset-child-element')).toBeEnabled()
+ expect(queryByTestId('div-element')).not.toBeEnabled()
+ expect(queryByTestId('div-child-element')).not.toBeEnabled()
+ expect(queryByTestId('div-enabled-element')).toBeEnabled()
+ expect(queryByTestId('div-enabled-child-element')).toBeEnabled()
+ expect(queryByTestId('div-element-2')).not.toBeEnabled()
+ expect(queryByTestId('non-focusable-child-element')).toBeEnabled()
+ expect(queryByTestId('nested-form-element')).not.toBeEnabled()
+ expect(queryByTestId('deep-select-element')).not.toBeEnabled()
+ expect(queryByTestId('deep-optgroup-element')).not.toBeEnabled()
+ expect(queryByTestId('deep-option-element')).not.toBeEnabled()
+
+ expect(queryByTestId('a-element')).toBeEnabled()
+ expect(queryByTestId('deep-a-element')).toBeEnabled()
+ expect(() =>
+ expect(queryByTestId('a-element')).not.toBeEnabled(),
+ ).toThrowError()
+ expect(() =>
+ expect(queryByTestId('deep-a-element')).not.toBeEnabled(),
+ ).toThrowError()
+ })
})
test('.toBeEnabled fieldset>legend', () => {
diff --git a/src/to-be-disabled.js b/src/to-be-disabled.js
index 9efe6f98..80778f1a 100644
--- a/src/to-be-disabled.js
+++ b/src/to-be-disabled.js
@@ -41,7 +41,11 @@ function canElementBeDisabled(element) {
}
function isElementDisabled(element) {
- return canElementBeDisabled(element) && element.hasAttribute('disabled')
+ if (canElementBeDisabled(element)) {
+ return element.hasAttribute('disabled')
+ } else {
+ return element.getAttribute('aria-disabled') === 'true'
+ }
}
function isAncestorDisabled(element) {
@@ -54,8 +58,8 @@ function isAncestorDisabled(element) {
function isElementOrAncestorDisabled(element) {
return (
- canElementBeDisabled(element) &&
- (isElementDisabled(element) || isAncestorDisabled(element))
+ isElementDisabled(element) ||
+ (canElementBeDisabled(element) && isAncestorDisabled(element))
)
}