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.
Examples
Section titled “Examples”<button>Click me</button><button onClick={handleClick}>Submit</button><button type="invalid">Click</button><button type="button">Click me</button><button type="submit">Submit form</button><button type="reset">Reset form</button>When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Deno:
button-has-typejsx-button-has-type - ESLint:
react/button-has-type
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.