primevue-mirror/doc/guides/accessibility/FormControlsDoc.vue

41 lines
1.7 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>
Native form elements should be preferred instead of elements that are meant for other purposes like presentation. As an example, button below is rendered as a form control by the browser, can receive focus via tabbing and can be used with
space key as well to trigger.
</p>
</DocSectionText>
2023-03-29 10:45:02 +00:00
<pre v-code><code>
2023-02-28 08:29:30 +00:00
&lt;button @click="onButtonClick(event)"&gt;Click&lt;/button&gt;
</code></pre>
2023-10-15 10:00:23 +00:00
<div class="doc-section-description mt-3">
2023-03-21 08:31:13 +00:00
<p>On the other hand, a fancy css based button using a div has no keyboard or screen reader support.</p>
</div>
2023-03-29 10:45:02 +00:00
<pre v-code><code>
2023-02-28 08:29:30 +00:00
&lt;div class="fancy-button" @click="onButtonClick(event)"&gt;Click&lt;/div&gt;
</code></pre>
2023-10-15 10:00:23 +00:00
<div class="doc-section-description mt-3">
2023-03-21 08:31:13 +00:00
<p>
<i>tabindex</i> is required to make a div element accessible in addition to use a keydown to bring the keyboard support back. To avoid the overload and implementing functionality that is already provided by the browser, native form
controls should be preferred.
</p>
</div>
2023-03-29 10:45:02 +00:00
<pre v-code><code>
2023-02-28 08:29:30 +00:00
&lt;div class="fancy-button" @click="onClick(event)" @keydown="onKeyDown(event)" tabindex="0"&gt;Click&lt;/div&gt;
</code></pre>
2023-10-15 10:00:23 +00:00
<div class="doc-section-description mt-3">
2023-03-21 08:31:13 +00:00
<p>Form components must be related to another element that describes what the form element is used for. This is usually achieved with the <i>label</i> element.</p>
</div>
2023-03-29 10:45:02 +00:00
<pre v-code><code>
2023-02-28 08:29:30 +00:00
&lt;label for="myinput"&gt;Username:&lt;/label&gt;
&lt;input id="myinput" type="text" name="username" /&gt;
</code></pre>
</template>