useButtonType
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
¥Diagnostic Category:
lint/a11y/useButtonType -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
¥Same as
react/button-has-type
-
¥How to configure
{ "linter": { "rules": { "a11y": { "useButtonType": "error" } } }}¥Description
强制对元素 button 使用属性 type
¥Enforces the usage of the attribute type for the element button
¥Examples
¥Invalid
<button>Do something</button>code-block.jsx:1:1 lint/a11y/useButtonType ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide an explicit type prop for the button element.
> 1 │ <button>Do something</button>
│ ^^^^^^^^
2 │
ℹ The default type of a button is submit, which causes the submission of a form when placed inside a `form` element. This is likely not the behaviour that you want inside a React application.
ℹ Allowed button types are: submit, button or reset
<button type="incorrectType">Do something</button>code-block.jsx:1:14 lint/a11y/useButtonType ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a valid type prop for the button element.
> 1 │ <button type=“incorrectType”>Do something</button>
│ ^^^^^^^^^^^^^^^
2 │
ℹ The default type of a button is submit, which causes the submission of a form when placed inside a `form` element. This is likely not the behaviour that you want inside a React application.
ℹ Allowed button types are: submit, button or reset
React.createElement('button');code-block.js:1:21 lint/a11y/useButtonType ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide an explicit type prop for the button element.
> 1 │ React.createElement(‘button’);
│ ^^^^^^^^
2 │
ℹ The default type of a button is submit, which causes the submission of a form when placed inside a `form` element. This is likely not the behaviour that you want inside a React application.
ℹ Allowed button types are: submit, button or reset
¥Valid
<> <button type="button">Do something</button> <button type={buttonType}>Do something</button></>¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号