有a< label>在React Native中标记?
我正在用反应本地制作形式。
(非本地)反应中的此形式的字段将是这样的:
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会说,就语义和可访问性而言,最接近的方法是:
I'd say the closest possible approach in terms of semantics and accessibility would be:
您可以将
&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.