question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disabled options lacks HTML attribute `disabled`

See original GitHub issue

Current results: When isOptionDisabled prop is present, it disables all selecting option value events (click, keyboard), but does not apply indication of the element being disabled aside from a different CSS class to the HTML element. This complicates integration testing efforts using tools such as @testing-library/react as there are no reliable HTML attributes to assert on.

Expected results: If option is disabled, an attribute disabled should be attached to the HTML element of the option

Potential issues According to W3Schools, only a small set of HTML tags natively support disabled and <div> (which is currently used for options) is not one of them. I’m uncertain what effects adding the attribute disabled to a <div> will have and I’m certain there’s a good reason for each option not being an <option> instead.

Thanks to audriusnavickasDB for providing a blueprint to this MR.

Codesandbox example: https://codesandbox.io/s/xenodochial-https-nnlgx?file=/example.js

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
Rall3ncommented, Sep 3, 2020

Wouldn’t the use of aria-role="option" and aria-disabled="true" suffice for this use case? Shouldn’t cause any major incompatability with customization.

0reactions
ebonowcommented, Jan 14, 2021

Wanted to do a bit of research on this to respond to this ticket appropriately.

TLDR; closing issue, disabled attribute is not applicable, may address aria-role, aria-disabled in other a11y PRs

@johannesleander

“I’m uncertain what effects adding the attribute disabled to a <div>”

disabled is not a valid attribute for a div element: source

The disabled attribute is supported by <button>, <command>, <fieldset>, 
<keygen>, <optgroup>, <option>, <select>, <textarea> and <input>.

@johannesleander

I’m certain there’s a good reason for each option not being an <option> instead.

The options are generated inside a div (and are divs themselves to allow more customization than a standard select option). That said, an Option element is only allowed as a child from any of the following: source

Contexts in which this element can be used:
As a child of a select element.
As a child of a datalist element.
As a child of an optgroup element.

@Rall3n

Wouldn’t the use of aria-role="option" and aria-disabled="true" suffice for this use case? Shouldn’t cause any major incompatibility with customization.

Yes. This seems like the appropriate answer given the information above. It should fit in with the existing accessibility PRs we have should we decide to incorporate it into the library as it would also be more consistent with how disabled options are treated in react-select (perceivably disabled and still focusable): source

Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.

For example, irrelevant options in a radio group may be disabled. Disabled elements might not receive focus from the tab order. For some disabled elements, applications might choose not to support navigation to descendants. In addition to setting the aria-disabled attribute, authors SHOULD change the appearance (grayed out, etc.) to indicate that the item has been disabled.

The state of being disabled applies to the current element and all focusable descendant elements of the element on which the aria-disabled attribute is applied.

The other question though, is this something a user can implement today? Yes.

const Option = props => {
  const innerProps = { ...props.innerProps, 'aria-disabled': props.isDisabled, 'aria-role': 'option' };
  return <components.Option {...props} innerProps={innerProps} />
}

So yes, a select DOM element can contain disabled options ~which make them unfocusable~. While we would like to make every attempt to be consistent, the HTML standards do not fit in this use case. There is an argument to make disabled options as non-focusable, but that feature request exists as another ticket already #3902

In further research, it seems that the origin of making disabled options focusable is based in accessibility and that indeed select options are focusable when using VoiceOver.

That all said, it seems appropriate to close this ticket out, but we can of course re-open if anyone has further thoughts or thinks this needs more review.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML attribute: disabled - HTML: HyperText Markup Language
This Boolean disabled attribute indicates that the user cannot interact with the control or its descendant controls.
Read more >
In HTML, what should happen to a selected, disabled option ...
When set, the disabled attribute has the following effects on an element: * Disabled controls do not receive focus. * Disabled controls are...
Read more >
HTML <option> disabled Attribute - GeeksforGeeks
The disabled attribute for <option> element in HTML is used to specify that the option value is disabled. A disabled option is un-clickable ......
Read more >
DISABLED attribute HTML & XHTML - Dottoro Web Reference
Sets the state of an object for user interaction. Disabled elements cannot have focus, do not receive or fire mouse events, cannot receive...
Read more >
HTML option disabled Attribute - W3Schools
The disabled attribute is a boolean attribute. When present, it specifies that an option should be disabled. A disabled option is unusable and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found