Basic Input
A labelled text input with helper text wired to it via aria-describedby.
6 個のフレームワーク初級
A search field with a leading icon and a clear button that appears once filled.
<!--
A search field with a magnifier in it still needs a real <label>. The design
has no room for one, so it is visually hidden rather than dropped: the icon is
aria-hidden decoration and the placeholder disappears on the first keystroke,
which would leave the field with no accessible name at all.
The clear button is a real <button> with its own name, not a click handler on
a <span> - it has to be reachable by Tab and Enter like any other action.
-->
<div class="icon-field">
<label class="icon-field__label" for="icon-field-search">Search components</label>
<div class="icon-field__box">
<svg class="icon-field__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
<circle cx="11" cy="11" r="7" />
<path d="m20 20-3.5-3.5" />
</svg>
<input
class="icon-field__input"
id="icon-field-search"
name="q"
type="search"
placeholder="Search components"
value="gradient"
/>
<button class="icon-field__clear" type="button" aria-label="Clear search">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
<path d="M18 6 6 18M6 6l12 12" />
</svg>
</button>
</div>
</div>
<script>
document.querySelectorAll('.icon-field').forEach(function (root) {
var input = root.querySelector('.icon-field__input');
var clear = root.querySelector('.icon-field__clear');
// The clear button only exists when there is something to clear - an
// always-visible X on an empty field is a control that does nothing.
function sync() {
clear.hidden = input.value.length === 0;
}
input.addEventListener('input', sync);
clear.addEventListener('click', function () {
input.value = '';
sync();
input.focus();
});
sync();
});
</script>| Prop | 型 | デフォルト | 説明 |
|---|---|---|---|
label必須 | string | - | 読み込み中に読み上げられるアクセシブルなラベル。 |
icon | ReactNode | - | コンテンツと並べて表示されるアイコン要素。 |
value必須 | string | - | 指標の現在値。フォーマット済みの文字列を渡します。 |
disabled | boolean | false | 操作を無効にし、コントロールを淡色表示にします。 |
The label renders `sr-only`, not omitted: the icon is `aria-hidden` decoration and the placeholder vanishes on the first keystroke, so without a real label the field has no accessible name at exactly the moment it matters. Swap the magnifier for any 24×24 stroke icon - it is drawn with `currentColor`, so it follows the field into dark mode. The clear button is a real `<button>` with its own name, reachable by Tab, and it only exists when there is something to clear; an always-visible X on an empty field is a control that does nothing. Use `px-9` on the input to keep the value from sliding under either affordance.