有a< label>在React Native中标记?

发布于 2025-02-13 07:07:35 字数 820 浏览 3 评论 0原文

我正在用反应本地制作形式。
(非本地)反应中的此形式的字段将是这样的:

<div>
  <label htmlFor="lastName">Last Name:</label>
  <input type="text" id="lastName" />
</div>

或在普通html中:

<div>
  <label for="lastName">Last Name:</label>
  <input type="text" id="lastName">
</div>

出于可访问性原因,我发现标签标签很重要。 我发现的每个教程都只使用占位符,我找不到&lt; label&gt;的任何参考文献。 当用户开始键入时,占位符消失,这使页面访问较低。

&lt; label&gt;标签也具有将焦点引导到输入时的优势。
这意味着单击&lt; label htmlfor =“ lastname”&gt;姓氏:&lt;/label&gt;提示用户在字段中输入&lt; input>&lt; input type =“ text” text“ text” id“ id” id =“ lastname” /&gt; < /code>。

由于这些原因,使用&lt; text&gt;标记为&lt; label&gt;并不理想。

I'm making a form in React native.
A field in this form in (non-native) React would be like this:

<div>
  <label htmlFor="lastName">Last Name:</label>
  <input type="text" id="lastName" />
</div>

Or in plain html:

<div>
  <label for="lastName">Last Name:</label>
  <input type="text" id="lastName">
</div>

I find the label tag important for accessibility reasons.
Every tutorial I found uses only placeholders and I couldn't find any reference for <label> in the react native documentation.
The placeholder disappears as the user starts typing, which makes the page less accessible.

The <label> tag also has the advantage of directing focus to the input when clicked.
This means a click on <label htmlFor="lastName">Last Name:</label> prompts the user to input in the field <input type="text" id="lastName" />.

For these reasons using <Text> tag as a <label> is not ideal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏日落 2025-02-20 07:07:35

我会说,就语义和可访问性而言,最接近的方法是:

<View>
  <Text aria-label="Label for Username" nativeID="labelUsername">Username</Text>
  <TextInput aria-label="input" aria-labelledby="labelUsername" />
</View>

I'd say the closest possible approach in terms of semantics and accessibility would be:

<View>
  <Text aria-label="Label for Username" nativeID="labelUsername">Username</Text>
  <TextInput aria-label="input" aria-labelledby="labelUsername" />
</View>
给不了的爱 2025-02-20 07:07:35

您可以将&lt; view&gt;用作您的&lt; div&gt; and &lt; text&gt;作为您的&lt; label&gt; 。

&lt; input&gt;&lt; textInput&gt;

,然后您只需为您的需求设计元素即可。

You can use <View> as your <div> and <Text> as your <label>.

<input> is <TextInput>

then you just have to style the elements to your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文