Skip to content

buttonTypes

Reports button elements without an explicit type attribute.

✅ This rule is included in the jsx logical preset.

Button elements without an explicit type attribute default to type="submit", which can cause unintended form submissions. This rule requires that all <button> elements have an explicit type attribute set to one of the valid values: "button", "submit", or "reset".

Specifying an explicit type makes the button’s behavior clear and prevents accidental form submissions.

<button>Click me</button>
<button onClick={handleClick}>Submit</button>
<button type="invalid">Click</button>

If your codebase exclusively uses buttons in forms where the default submit behavior is never a concern, you might choose to disable this rule. However, it’s generally recommended to be explicit about button types for clarity and maintainability.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.