noDisabledAttribute (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.6.7 - Diagnostic Category:
lint/nursery/noDisabledAttribute - This rule has an unsafe fix.
- The default severity of this rule is warning.
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noDisabledAttribute": "error" } } }}Description
Section titled “Description”Discourages the disabled attribute on form controls and on elements that act as buttons.
This is an opinionated usability rule, not a Web Content Accessibility Guidelines (WCAG)
requirement. A form control with the native disabled attribute can’t receive keyboard
focus, so people who move through a page with the Tab key skip over it. Keeping an
unavailable control focusable can make it easier to discover with a keyboard or assistive
technology.
The rule reports the following elements when disabled is set:
- Buttons:
buttonelements, andinputelements with thebutton,submit,reset, orimagetype. Abuttonis still reported when a role other thanbuttonis assigned, becausedisabledcontinues to change its native behavior. - Fields that support the
readOnlyattribute:textareaelements, andinputelements whose type accepts typed input, such astext,email,number, ordate. Aninputwith notype, or with atypethat browsers don’t recognize, is a text field. - Other form controls:
selectelements, andinputelements with thecheckbox,radio,range,color, orfiletype. fieldsetelements, because a disabledfieldsetdisables every form control inside it.- Built-in elements that aren’t form controls and whose first valid explicit role is
button. Thedisabledattribute has no effect on these elements.
The rule doesn’t report option and optgroup elements, input elements with the
hidden type, or input elements whose type is a dynamic expression or can come from
a spread attribute.
Replacing disabled
Section titled “Replacing disabled”The unsafe fix depends on the reported element:
- For fields that support it, the fix replaces
disabledwithreadOnly. A read-only field can receive focus and can’t be edited. Unlike a disabled field, its value is still submitted with the form, and browsers don’t apply disabled styling to it. - For buttons, other form controls, and elements with the
buttonrole, the fix replacesdisabledwitharia-disabled. The ARIA attribute only exposes the disabled state to assistive technology. It does not prevent pointer or keyboard activation, change form submission or validation, omit values from submitted data, or add disabled styling. Implement those behaviors and provide disabled styling, including for forced-colors mode. - A
fieldsethas no fix. Mark each form control inside it instead. Disabling afieldsetcan be appropriate when the whole group doesn’t apply to the user, for example the details of a second applicant when there is only one applicant. In that case, suppress the diagnostic.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<button disabled>Save</button>code-block.jsx:1:9 lint/nursery/noDisabledAttribute FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid the native disabled attribute on this button.
> 1 │ <button disabled>Save</button>
│ ^^^^^^^^
2 │
ℹ A disabled form control can't receive keyboard focus, so it can't be reached with the Tab key.
ℹ Replace it with aria-disabled, which only exposes the disabled state to assistive technology. It does not suppress pointer or keyboard activation, form submission or validation, or apply disabled styling. Implement those behaviors, including forced-colors styling.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use aria-disabled instead.
1 │ <button·aria-disabled="true">Save</button>
│ +++++ +++++++
<input type="email" disabled />code-block.jsx:1:21 lint/nursery/noDisabledAttribute FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid the native disabled attribute on this field.
> 1 │ <input type="email" disabled />
│ ^^^^^^^^
2 │
ℹ A disabled form control can't receive keyboard focus, so it can't be reached with the Tab key.
ℹ Replace it with readOnly, which keeps the field focusable and prevents edits. Unlike a disabled field, a read-only field is still submitted with its form and doesn't get disabled styling.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use readOnly instead.
1 │ - <input·type="email"·disabled·/>
1 │ + <input·type="email"·readOnly·/>
2 2 │
<select disabled><option>Monthly</option></select>code-block.jsx:1:9 lint/nursery/noDisabledAttribute FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid the native disabled attribute on this form control.
> 1 │ <select disabled><option>Monthly</option></select>
│ ^^^^^^^^
2 │
ℹ A disabled form control can't receive keyboard focus, so it can't be reached with the Tab key.
ℹ Replace it with aria-disabled, which only exposes the disabled state to assistive technology. It does not suppress pointer or keyboard activation, form submission or validation, or apply disabled styling. Implement those behaviors, including forced-colors styling.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use aria-disabled instead.
1 │ <select·aria-disabled="true"><option>Monthly</option></select>
│ +++++ +++++++
<fieldset disabled><input type="text" /></fieldset>code-block.jsx:1:11 lint/nursery/noDisabledAttribute ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid the native disabled attribute on this fieldset.
> 1 │ <fieldset disabled><input type="text" /></fieldset>
│ ^^^^^^^^
2 │
ℹ A disabled fieldset disables every form control inside it, so none of them can be reached with the Tab key.
ℹ Mark each form control inside the fieldset instead: use readOnly on fields that support it and aria-disabled on other controls.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<div role="button" disabled>Save</div>code-block.jsx:1:20 lint/nursery/noDisabledAttribute FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The disabled attribute has no effect on this element.
> 1 │ <div role="button" disabled>Save</div>
│ ^^^^^^^^
2 │
ℹ The button role changes accessibility semantics but does not add native button behavior.
ℹ Replace it with aria-disabled, which only exposes the disabled state to assistive technology. It does not suppress pointer or keyboard activation, form submission or validation, or apply disabled styling. Implement those behaviors, including forced-colors styling.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use aria-disabled instead.
1 │ <div·role="button"·aria-disabled="true">Save</div>
│ +++++ +++++++
<> <button aria-disabled="true">Save</button> <input type="email" readOnly /> <select aria-disabled="true"><option>Monthly</option></select> <input type="hidden" disabled /></>References
Section titled “References”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.