mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
docs(form): add form label related FAQ (#52153)
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run
* docs(form): add form label related FAQ ref: - https://github.com/ant-design/ant-design/issues/47031 - https://github.com/ant-design/ant-design/issues/43175 - https://github.com/ant-design/ant-design/issues/52152 * chore: format * chore: update * chore: update * Update components/form/index.zh-CN.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: 𝑾𝒖𝒙𝒉 <wxh16144@qq.com> --------- Signed-off-by: 𝑾𝒖𝒙𝒉 <wxh16144@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
This commit is contained in:
parent
bb38ef51f1
commit
0175ea0dc1
@ -718,3 +718,16 @@ const MyInput = (props) => (
|
||||
<MyInput />
|
||||
</Form.Item>;
|
||||
```
|
||||
|
||||
### Why does clicking the label in the form change the component state?
|
||||
|
||||
> Related issue: [#47031](https://github.com/ant-design/ant-design/issues/47031), [#43175](https://github.com/ant-design/ant-design/issues/43175), [#52152](https://github.com/ant-design/ant-design/issues/52152)
|
||||
|
||||
Form label use [HTML label](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label) elements to wrap form controls, which focuses the corresponding control when clicked. This is the native behavior of label elements, designed to improve accessibility and user experience. This standard interaction pattern makes it easier for users to interact with form controls. If you need to disable this behavior, you can use `htmlFor={null}`, though it's generally not recommended.
|
||||
|
||||
```diff
|
||||
- <Form.Item name="switch" label="Switch">
|
||||
+ <Form.Item name="switch" label="Switch" htmlFor={null}>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
```
|
||||
|
@ -718,6 +718,19 @@ const MyInput = (props) => (
|
||||
</Form.Item>;
|
||||
```
|
||||
|
||||
### 为什么表单点击 label 会更改组件状态?
|
||||
|
||||
> 相关 issue:[#47031](https://github.com/ant-design/ant-design/issues/47031),[#43175](https://github.com/ant-design/ant-design/issues/43175), [#52152](https://github.com/ant-design/ant-design/issues/52152)
|
||||
|
||||
表单 label 使用 [HTML label](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/label) 元素来包裹表单控件,从而实现点击 label 时聚焦到对应控件。这是 label 元素的原生行为,用于提升可访问性和用户体验,这种标准交互模式能让用户更容易操作表单控件。如果你不希望这种行为,可通过 `htmlFor={null}` 属性解除关联,通常不建议这样做。
|
||||
|
||||
```diff
|
||||
- <Form.Item name="switch" label="Switch">
|
||||
+ <Form.Item name="switch" label="Switch" htmlFor={null}>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
```
|
||||
|
||||
### 有更多参考文档吗?
|
||||
|
||||
- 你可以阅读[《antd v4 Form 使用心得》](https://zhuanlan.zhihu.com/p/375753910)获得一些使用帮助以及建议。
|
||||
|
Loading…
Reference in New Issue
Block a user