From 0175ea0dc1f6a002f590ea7b78d12b7ec227d747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=91=BE=F0=9D=92=96=F0=9D=92=99=F0=9D=92=89?= Date: Thu, 2 Jan 2025 17:37:23 +0800 Subject: [PATCH] docs(form): add form label related FAQ (#52153) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Signed-off-by: 𝑾𝒖𝒙𝒉 --------- Signed-off-by: 𝑾𝒖𝒙𝒉 Co-authored-by: afc163 --- components/form/index.en-US.md | 13 +++++++++++++ components/form/index.zh-CN.md | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/components/form/index.en-US.md b/components/form/index.en-US.md index eac0d13cf5..6c3968548a 100644 --- a/components/form/index.en-US.md +++ b/components/form/index.en-US.md @@ -718,3 +718,16 @@ const MyInput = (props) => ( ; ``` + +### 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 +- ++ + + +``` diff --git a/components/form/index.zh-CN.md b/components/form/index.zh-CN.md index 093e094c9b..5fa7fd0058 100644 --- a/components/form/index.zh-CN.md +++ b/components/form/index.zh-CN.md @@ -718,6 +718,19 @@ const MyInput = (props) => ( ; ``` +### 为什么表单点击 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 +- ++ + + +``` + ### 有更多参考文档吗? - 你可以阅读[《antd v4 Form 使用心得》](https://zhuanlan.zhihu.com/p/375753910)获得一些使用帮助以及建议。