checked-requires-onchange-or-readonly
Configuration
Rule Details
Enforce using onChange or readOnly attribute when checked is used on an input element (and on React.createElement('input', ...) calls).
A controlled <input> whose checked value is fixed without an onChange handler can never be toggled by the user and triggers a React warning. This rule also forbids combining checked with defaultChecked, since an input is either controlled (checked) or uncontrolled (defaultChecked), never both.
The check applies to every input element carrying checked, regardless of its type.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
ignoreMissingProperties
Default: false. When true, an input with checked but no onChange / readOnly is allowed (the missingProperty diagnostic is suppressed).
Examples of correct code for this rule with { "ignoreMissingProperties": true }:
ignoreExclusiveCheckedAttribute
Default: false. When true, combining checked and defaultChecked is allowed (the exclusiveCheckedAttribute diagnostic is suppressed).
Examples of correct code for this rule with { "ignoreExclusiveCheckedAttribute": true }:
Limitations
- Detects
<pragma>.createElement(...)where<pragma>defaults toReactand can be overridden viasettings.react.pragma(e.g."Foo"→Foo.createElement(...)). DestructuredcreateElement(e.g.import { createElement } from 'react') and@jsxcomment pragmas are not supported.