Skip to content

CSS: form-field

.instui-form-field — フォームフィールドのラッパー:ラベル、そのコントロール、そしてインライン、必須、または読み取り専用のレイアウト。

エラーメッセージはフィールドのコントロールが :user-invalid(ユーザーが操作した後)になるか、-invalid クラスを追加するまで表示されません。ラベルをコントロールの横に置くには -layout-inline を、上に置くには -layout-stacked を使用します。また、ラベル、コントロール、メッセージ間の独自の gap を設定します。チェーンした -gap-* スペーシングユーティリティ修飾子が組み込み値を上書きします。

Source: form-field.css

アクセシビリティ

<label> 要素はコントロールをラップするため、ラベルのテキストはネイティブにそれを指します。必須のアスタリスクは装飾的なもので支援技術からは隠すべき(aria-hidden)であり、エラーメッセージはコントロールが :user-invalid になるか、-invalid クラスを追加したときに表示されます。

使用法

css
@import "@pantoken/components/components.css";
@import "@pantoken/components/form-field.css";

html
<label class="instui-form-field">
  <span class="label">Email address</span>
  <span class="controls"><input class="instui-text-input" type="email" placeholder="[email protected]"></span>
  <div class="instui-form-field-messages">
    <span class="instui-form-field-message -type-hint">We'll never share it.</span>
    <span class="instui-form-field-message -type-error">Enter a valid email address.</span>
  </div>
</label>

構造

text
.instui-form-field
  .label
  .controls
    text-input (component)
  form-field-messages (component)
flowchart TD n0[".instui-form-field"]:::cssdoc-root n1(".label"):::cssdoc-part n2(".controls"):::cssdoc-part n3(["text-input"]):::cssdoc-component n4(["form-field-messages"]):::cssdoc-component n0 --> n1 n2 --> n3 n0 --> n2 n0 --> n4 click n3 "/api/css/text-input.md" click n4 "/api/css/form-field-messages.md" classDef cssdoc-root stroke-width:1px; classDef cssdoc-part stroke-width:1px; classDef cssdoc-slot stroke-width:1px; classDef cssdoc-component stroke-width:1px;

修飾子

修飾子説明
.-inlineインラインレイアウト(-layout-inline の省略形)。
.-invalid無効(エラー)状態。
.-label-align-endラベルテキストを右寄せ(終了位置揃え)にします。
.-label-align-startラベルテキストを左寄せ(開始位置揃え)にします。
.-layout-inlineインラインレイアウト:ラベルがコントロールの横に配置されます。
.-layout-stacked積み重ね(スタック)レイアウト:ラベルがコントロールの上に配置されます。
.-readonly読み取り専用状態。
.-v-align-bottomラベルをコントロールと下揃えにします。
.-v-align-topラベルをコントロールと上揃えにします。

パーツ

パート説明
.controlsラベルの横または下にあるコントロール領域。
.labelフィールドのラベル。

疑似要素

疑似要素説明
::afterフィールドが必須の場合、ラベルテキストの後に装飾的な必須アスタリスクをレンダリングします。

状態

状態説明
:required

使用トークン

Token
--instui-component-form-field-layout-asterisk-color<color>LightDarklight-dark(#CF1F24, #FA917F)
--instui-component-form-field-layout-font-family[ <font-family-name> | <generic-font-family> ]#Atkinson Hyperlegible Next, "Helvetica Neue", Helvetica, Arial, sans-serif
--instui-component-form-field-layout-font-size<length>1rem
--instui-component-form-field-layout-font-weight<integer>400
--instui-component-form-field-layout-gap-inputs<length>0.75rem
--instui-component-form-field-layout-gap-primitives<length>0.5rem
--instui-component-form-field-layout-line-height<length>1.125rem
--instui-component-form-field-layout-readonly-text-color<color>LightDarklight-dark(#576773, #AAB0B5)
--instui-component-form-field-layout-text-color<color>LightDarklight-dark(#273540, #ffffff)

ブラウザ対応

  • CSS の @scope at-rule を使って要素スタイルを含みます;最新の Chromium、Firefox、または Safari が必要です。

サブコンポーネント

関連項目

  • form-field-messages — フィールドのヒント、エラー、成功メッセージをレンダリングします。
  • form-field-group — 関連フィールドを共有のレジェンド下にグループ化します。