Skip to content

autoFocusProps

Reports autoFocus props that are not set to false.

✅ This rule is included in the jsx logical and logicalStrict presets.

Auto-focusing elements automatically grab the user’s focus, which is generally disruptive behavior. It can be particularly disruptive to users who rely on screen readers and/or keyboard navigation.

Consider letting users focus elements manually instead.

<
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
HTMLAttributes<HTMLButtonElement>.autoFocus?: boolean | undefined
autoFocus
/>
<
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
autoFocus="true" />
Error ts(2322) ― Type 'string' is not assignable to type 'boolean | undefined'.
<
JSX.IntrinsicElements.input: DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>
input
HTMLAttributes<HTMLInputElement>.autoFocus?: boolean | undefined
autoFocus
={true} />

If you have specific use cases where auto-focus is necessary for user experience (such as modal dialogs), you may want to disable this rule for those specific cases. Auto-focusing elements should only sparingly be used when explicitly triggered by users.

Made with ❤️‍🔥 around the world by the Flint team and contributors.