Fieldset
関連するフォームコントロールをlegendの下にグループ化します。
fieldsetに関するWAI-ARIA APGパターンはありません。Fieldsetはネイティブの<fieldset>要素および<legend>要素をレンダリングするため、グループはrole="group"を取得し、そのlegendによって名前が付けられます。
import { component$, useStyles$ } from '@builder.io/qwik';
import { Fieldset } from '@leve-ui/fieldset';
import styles from './default.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Fieldset.Root class="fieldset-default">
<Fieldset.Legend class="fieldset-default-legend">Shipping method</Fieldset.Legend>
<label class="fieldset-default-option">
<input class="fieldset-default-radio" type="radio" name="shipping" value="standard" />{' '}
Standard
</label>
<label class="fieldset-default-option">
<input class="fieldset-default-radio" type="radio" name="shipping" value="express" />{' '}
Express
</label>
</Fieldset.Root>
);
});.fieldset-default {
display: flex;
flex-direction: column;
gap: 10px;
width: 280px;
margin: 0;
padding: 0;
border: none;
font-family: inherit;
}
.fieldset-default-legend {
padding: 0;
margin-bottom: 10px;
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
/* Each option is a selectable card */
.fieldset-default-option {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.fieldset-default-option:has(input:checked) {
border-color: #009dfd;
background: light-dark(#daf0ff, #009dfd26);
}
.fieldset-default-radio {
width: 16px;
height: 16px;
margin: 0;
accent-color: #009dfd;
}
.fieldset-default-radio:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}インストール#
個別のパッケージをインストールするか、@leve-ui/coreを使用してすべてのコンポーネントを一度に取得します。
pnpm add @leve-ui/fieldsetnpm install @leve-ui/fieldsetyarn add @leve-ui/fieldsetbun add @leve-ui/fieldsetpnpm add @leve-ui/corenpm install @leve-ui/coreyarn add @leve-ui/corebun add @leve-ui/core構造#
import { Fieldset } from '@leve-ui/fieldset'; // or '@leve-ui/core'
<Fieldset.Root>
<Fieldset.Legend />
</Fieldset.Root>
| パーツ | 要素 | 説明 |
|---|---|---|
Fieldset.Root | <fieldset> | フォームコントロールをグループ化します。 |
Fieldset.Legend | <legend> | グループのラベル。Rootの最初の子として配置します。 |
例#
Disabled#
Rootのdisabledは、ネイティブの<fieldset disabled>と同様に、内部のすべてのフォームコントロールを無効化します。内部にあるleve-uiのコントロール(Checkbox、Switch、Radio Group、Toggle、Toggle Group、Field)も無効化され、data-disabledを描画してクリックを無視します。HTMLと同様に、Legend内のコントロールはそのFieldsetによって無効化されることはなく、ネストされたFieldsetは祖先が無効化されている場合に無効化されます。
import { component$, useStyles$ } from '@builder.io/qwik';
import { Fieldset } from '@leve-ui/fieldset';
import { Switch } from '@leve-ui/switch';
import styles from './disabled.css?inline';
export default component$(() => {
useStyles$(styles);
// A disabled Fieldset also disables the leve-ui controls inside it
return (
<Fieldset.Root disabled class="fieldset-disabled">
<Fieldset.Legend class="fieldset-disabled-legend">Notifications</Fieldset.Legend>
<Switch.Root defaultChecked class="fieldset-disabled-switch">
<Switch.Label class="fieldset-disabled-label">Email</Switch.Label>
<Switch.Control class="fieldset-disabled-control">
<Switch.Thumb class="fieldset-disabled-thumb" />
</Switch.Control>
</Switch.Root>
<Switch.Root class="fieldset-disabled-switch">
<Switch.Label class="fieldset-disabled-label">Push</Switch.Label>
<Switch.Control class="fieldset-disabled-control">
<Switch.Thumb class="fieldset-disabled-thumb" />
</Switch.Control>
</Switch.Root>
</Fieldset.Root>
);
});.fieldset-disabled {
font-family: inherit;
display: flex;
flex-direction: column;
gap: 12px;
width: 240px;
margin: 0;
padding: 0;
border: none;
}
.fieldset-disabled-legend {
padding: 0;
margin-bottom: 4px;
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.fieldset-disabled-legend[data-disabled] {
opacity: 0.5;
}
.fieldset-disabled-switch {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.fieldset-disabled-label {
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.fieldset-disabled-control {
display: inline-flex;
align-items: center;
flex-shrink: 0;
width: 36px;
height: 20px;
padding: 2px;
border: none;
border-radius: 9999px;
background: light-dark(#cbd5e1, #ffffff3d);
cursor: pointer;
}
.fieldset-disabled-control[data-state="checked"] {
background: #009dfd;
}
.fieldset-disabled-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.fieldset-disabled-thumb {
display: block;
width: 16px;
height: 16px;
border-radius: 9999px;
background: #ffffff;
box-shadow: 0 1px 2px rgb(15 23 42 / 0.2);
transition: transform 150ms ease;
}
.fieldset-disabled-thumb[data-state="checked"] {
transform: translateX(16px);
}
/* The Fieldset passes its disabled state to the switches */
.fieldset-disabled-label[data-disabled],
.fieldset-disabled-control[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}APIリファレンス#
Root#
独自のpropはありません。 すべての<fieldset>属性を受け入れます。
| データ属性 | 値 |
|---|---|
data-leve-fieldset | 常に存在 |
data-disabled | 無効時に存在 |
disabledを含むすべてのpropsは、ネイティブの<fieldset>に渡されます。
Legend#
独自のpropはありません。 すべての<legend>属性を受け入れます。
| データ属性 | 値 |
|---|---|
data-leve-fieldset-legend | 常に存在 |
data-disabled | Rootが無効化されている場合に存在 |
アクセシビリティ#
- ネイティブの
<fieldset>は暗黙のrole="group"を持ち、Fieldset.Legendがグループのアクセシブルな名前を提供します。 - Rootが無効化されると、その内部のコントロールは無効化され、Tabキーによってスキップされます。ネイティブコントロールはブラウザによって、leve-uiコントロールはFieldsetを通じてスキップされます。
- Fieldset自体にはキーボード操作はありません。