-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
[New] no-disabled rule #830
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## main #830 +/- ##
=======================================
Coverage 99.22% 99.22%
=======================================
Files 98 99 +1
Lines 1419 1428 +9
Branches 479 481 +2
=======================================
+ Hits 1408 1417 +9
Misses 11 11
Continue to review full report at Codecov.
|
Can you elaborate on this? There's many perfectly reasonable cases where it's better to have an input be disabled. |
I am simply going off MDN on this:
|
I did read that, and that is the first time in my entire career I've heard that advice - and it seems a VERY strong position. Are there other references, a11y guidelines, ecosystem adoption, that confirm the opinion on MDN? |
@ljharb I can certainly do additional digging, but do you think there is a place for this plugin where maybe we warn others of this? I just learned of it today and I would prefer to give this concern exposure. |
I absolutely think that this PR is the correct place/way to handle this, assuming the concern is as urgent and valid as MDN implies. |
W3's best practices lists a few specific cases where
|
That suggests that it'd be better to forbid "disabled" by default only on those four kinds of elements (altho an option to forbid it "everywhere" is fine). Thoughts? |
To me, two key take-aways from WAI-Aria's section:
The second bullet refers to elements in a toolbar, but it seems like it could apply to any element. Eg I've seen it recommended that submit-buttons that are "disabled" until all required fields are completed should be focusable to ensure users can find it even before they complete the fields. I'm not sure what the eslint rule should be though.. Maybe it is reasonable to only default to the four types of composite widgets mentioned in the WAI-Aria section. But I'm not sure that it's intended to be a complete list. |
W3 states,
I think that means To me a question I'd like answered is if the **Edit: (when disabled) |
There’s a lot of things visually on a page that are hidden for non-visual users - borders, aspects of how a button looks, background colors and images - it doesn’t automatically make sense for something to be in the a11y tree just because it’s visible. That said, i can imagine a good chunk of the places I’ve used the disabled attribute in the past are things whose presence would be useful for a non-visual user to know about. To be honest, this really feels like a bug/flaw in the way the a11y tree is built - ie, that it shouldn’t be omitting these elements. To be forced to use an aria attribute seems pretty absurd; their purpose is to provide additional info, or to hack around non-semantic html. |
The attribute was brought up in a code review session today. I have a list of actions I'd like the user to take to onboard. However, they are not able to manually click on these checkboxes, but are there to serve as a visual cue if the user completed the actions. In this case, I chose to use |
The choice is meaningful and important; but it really does seem like the default should be to include them, and the aria override should be to hide them. |
Great conversation here. This came up at work the other day and Matt King also recommended not using the I'm in favor of this rule. Let me review the code. I think we should get it in. |
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.
@courtyenn this is really fantastic! It's close, just a few nits to clean up. The basic logic is there. This is a great idea. Thank you for proposing it!
src/rules/no-disabled.js
Outdated
JSXAttribute: (attribute) => { | ||
// Only monitor eligible elements for "disabled". | ||
const type = elementType(attribute.parent); | ||
if (!DEFAULT_ELEMENTS.includes(type)) { |
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.
I recall that we have support issues with includes
and older versions of Node. Could you rewrite this as a for
loop?
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.
@ljharb do you have an issue with includes
?
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.
I have a much larger issue with loops :-) we support down to eslint 3, which requires node 4+, which lacks .includes
. However, we can and should use the array-includes
package for this, which will prefer the native method when available.
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.
Got it. I will endeavor to commit this detail to memory for the next time =D
@jessebeach is there any effort to fix this in browsers? semantic non-aria attributes are supposed to be the best approach, and this seems like the odd one out. |
Agreed. I haven't heard any rumblings of changing this behavior and my sense here is that this horse is long out of the barn, never to return. I think they just got the default behavior wrong here, probably because this attribute predates or is contemporaneous with assistive tech cursor traversal. @courtyenn I think what @ljharb is insinuating, is that this rule is encouraging counter-intuitive behavior. It runs contrary to the general heuristic "Use semantic HTML first; ARIA second or not at all". So the explanation for this rule should acknowledge that this behavior runs counter to the general advice: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/830/files#diff-1cf5c60cfe95228a04407905406f8fc98a66b9b0d0bc27f474e23a8976f8b206R3 |
@@ -3,8 +3,7 @@ | |||
Rule that `disabled` prop should be cautioned on elements. Disabling interactive elements removes the element from the accessibility tree. Consider using `aria-disabled`. | |||
|
|||
## Rule details | |||
|
|||
Warns usage of `disabled` property. | |||
The general consensus is that `disabled` should be used with specific intent. It goes against intuition since `disabled` is a native HTML attribute, which disables. However, from a usability stand-point it is not a good UX for screen readers: It removes the element from the a11y tree, and may omit critical information. It is best to use `aria-disabled` and add the additional JS logic to "disable" the element. |
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.
The general consensus is that `disabled` should be used with specific intent. It goes against intuition since `disabled` is a native HTML attribute, which disables. However, from a usability stand-point it is not a good UX for screen readers: It removes the element from the a11y tree, and may omit critical information. It is best to use `aria-disabled` and add the additional JS logic to "disable" the element. | |
The general consensus is that `disabled` should be used with specific intent. It goes against intuition since `disabled` is a native HTML attribute, which disables. However, from a usability standpoint it is not a good UX for screen readers: it removes the element from the a11y tree, and may omit critical information. It is best to use `aria-disabled` and add additional JS logic to "disable" the element. |
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.
@courtyenn this is really close! Just a few copy changes to tighten up the documentation. This is really good stuff!
Rule that `disabled` prop should be cautioned on elements. Disabling interactive elements removes the element from the accessibility tree. Consider using `aria-disabled`. | ||
|
||
## Rule details | ||
The general consensus is that `disabled` should be used with specific intent. It goes against intuition since `disabled` is a native HTML attribute, which disables. However, from a usability stand-point it is not a good UX for screen readers: It removes the element from the a11y tree, and may omit critical information. It is best to use `aria-disabled` and add the additional JS logic to "disable" the element. |
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.
I'm going to be a bit more prescriptive here with this text. Apologies for the heavy-handed editing:
"The disabled
attribute renders an HTML form element inoperable -- it cannot be focused or pressed. Disabled elements are visually rendered with lighter backgrounds and borders, indicating through visual affordance that they are present but inoperable. Unfortunately, an HTML form element with the disabled
attribute is not rendered to the Accessibility Tree, so if a user cannot perceive the interface visually, they will not perceive the disabled form elements.
For this reason, we recommend that authors not use the disabled
HTML attribute, which admittedly goes against the common best practice to use semantic HTML. Instead, use aria-disabled
to indicate to assistive technology agents that an element is disabled. Additionally, use CSS to alter the appearance of an element to give it the visual appearance of a disabled state and use JavaScript to prevent the default behaviors of the element."
generateObjSchema, | ||
} from '../util/schemas'; | ||
|
||
const warningMessage = 'The disabled prop removes the element from being detected by screen readers.'; |
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.
"The disabled attribute makes the element imperceivable to assistive technology agents, like screen readers."
Just a small nit that an attribute
is a HTML feature, whereas a prop
is a DOM concept. In this case, we are detecting the presence of an attribute, not a prop.
Also, we should avoid being screen-reader-centric. There are many assistive technology agents. Screen readers are common and probably what a developer is familiar with, so it helps to mention them. We just want to be sure we leave room for the full spectrum of agents that we need to support.
@courtyenn it looks like the JS error in the tests is caused by the changes you introduced. Could you have a look? |
I didn't see a contribution guideline. I still need to test this out, but just thought I'd submit a PR with the proposed changes.
According to MDN:
Sources: