---
title: "カラーフィールド"
description: "フォームのフィールドとして、1 つの色を設定できるようにします。読んで、入力して、貼り付けられるテキストの値と、その横の色見本と、ピッカーを求めるボタンがあり、テキストフィールドと同じ見た目と寸法です。"
url: "https://tanrei.chnotchy.com/ja/components/color-field/"
last_updated: 2026-10-23T21:17:12.000Z
---

# カラーフィールド

> フォームのフィールドとして、1 つの色を設定できるようにします。読んで、入力して、貼り付けられるテキストの値と、その横の色見本と、ピッカーを求めるボタンがあり、テキストフィールドと同じ見た目と寸法です。

## 概要

カラーフィールドは、ユーザーが色を値として設定する場所に使います。テーマのブランドカラーや、ラベルやカテゴリーの色などです。ユーザーは値を読み、入力し、ほかのツールから貼り付け、テキストの横の色見本で確かめます。フィールドは、同じバリアントとサイズのテキストフィールドと同じ見た目と寸法です。

**構成要素**は、[フィールド](https://tanrei.chnotchy.com/ja/components/field/)と[カラー入力欄](https://tanrei.chnotchy.com/ja/components/color-input/)です。フィールドは枠で、ラベル、必須または任意の印、補足、エラーを受け持ちます。カラー入力欄はコントロールで、ボックス、色見本、テキストとしての値、ピッカーのボタンを受け持ちます。カラーフィールドは自分では何も描かず、自分のトークンも持ちません。プロパティはすべて、2 つのどちらかのプロパティで、そのまま渡されます。

置かれた場所の幅いっぱいに広がるブロックで、ボックスもその幅いっぱいに広がります。自分の幅は持ちません。フィールドを狭くするには、置く場所を狭くします。すでにフィールドなので、[フィールド](https://tanrei.chnotchy.com/ja/components/field/)の中には入れません。

ピッカーは自分では描きません。`picker` を付けると、末尾側のボタンがピッカーを求めます。ブラウザーのピッカーか、プロダクトが表示するサーフェスです。

Web では `<tanrei-color-field>` です。ほかのプラットフォームはまだ実装していません。

### 使い方

`value` は、番号記号と小文字の 16 進数 6 桁（`#0f766e`）か、色がないことを表す空文字列です。入力途中のテキストになることはありません。入力欄にあるものが色でない間、`value` は空です。

**Web**

```html
<form>
  <tanrei-color-field name="brand" label="ブランドカラー" value="#0f766e"
    required required-text="必須"
    supporting-text="6 桁の 16 進数で入力します。例：#0f766e"
    invalid-text="6 桁の 16 進数で入力してください。例：#0f766e"
    picker picker-label="色を選択"></tanrei-color-field>
</form>

<script type="module">
  import '@tanrei/web/components/color-field';

  const brand = document.querySelector('tanrei-color-field');
  // 値が変わりました。色か空文字列で、value はすでに新しい値です。
  brand.addEventListener('input', () => preview(brand.value));
  // ユーザーが変わった値を確定しました。フォーカスが離れたとき、Enter、ピッカーが閉じたときです。
  brand.addEventListener('change', () => save(brand.value));
  // 色ではないテキストが確定されました。フィールドはテキストを残し、invalidText を表示します。
  // detail.message が伝えるのも、この invalidText です。
  brand.addEventListener('entryerror', (e) => console.log(e.detail.text, e.detail.message));
  // プロダクト側のピッカーを表示するには、要求をキャンセルして開き、選ばれた色を value に設定します。
  brand.addEventListener('pickerrequest', (e) => {
    e.preventDefault();
    openMyPicker(e.detail.value).then((color) => (brand.value = color));
  });
</script>
```

**React**

```tsx
import { ColorField } from '@tanrei/react';

<ColorField label="ブランドカラー" value={brand} picker pickerLabel="色を選択"
  invalidText="6 桁の 16 進数で入力してください。例：#0f766e"
  onChange={(event) => setBrand(event.currentTarget.value)} />
```

### 1 つ下の階層

同じフィールドを 2 つの構成要素から自分で書いても、見た目は同じで、支援技術にとっても、同じ名前、説明、状態を持つ同じテキストボックスになります。

```html
<tanrei-field label="ブランドカラー" required required-text="必須"
  supporting-text="6 桁の 16 進数で入力します。例：#0f766e">
  <tanrei-color-input name="brand" value="#0f766e"
    invalid-text="6 桁の 16 進数で入力してください。例：#0f766e"
    picker picker-label="色を選択"></tanrei-color-input>
</tanrei-field>
```

カラーフィールドにない並べ方が必要なときに、1 つ下の階層で書きます。

| 必要なもの | 使うもの |
| --- | --- |
| ラベル、ボックス、補足、エラー | カラーフィールド |
| 枠の中、ボックスの横か下に置く自分の要素 | [フィールド](https://tanrei.chnotchy.com/ja/components/field/)に、[カラー入力欄](https://tanrei.chnotchy.com/ja/components/color-input/)と自分の要素を入れる |
| ボックスだけ。行や列がすでに色の名前を示している（パレットのトーン、テーブルのセル） | [カラー入力欄](https://tanrei.chnotchy.com/ja/components/color-input/)を単独で使い、入力欄の `label` で名前を付ける |

1 つ下の階層で変わるのは、何をどこに指定するかです。`name` と `value` はカラー入力欄に指定し、フォームに加わるコントロールもイベントが届く先も入力欄になります。`label`、`error`、`disabled`、必須の指定はフィールドに残り、フィールドがコントロールに渡します。入力欄自身のものは指定しません。カラーフィールドが行い、フィールドとカラー入力欄を自分で書いたものが行わないことは、ありません。

## 仕様

### フィールド

| パーツ | 内容 |
| --- | --- |
| ラベル | コンテナの上（`stacked`）ではフィールドが描き、コンテナの中で浮く（`filled`、`outlined`）ときはカラー入力欄が描きます。描いても `labelHidden` で隠しても、アクセシブルネームになります |
| 必須・任意の印 | ラベルの後ろ。`required` では必須のタグ、アスタリスク、または印なし。`optional` では任意のタグ |
| 色見本 | コンテナの先頭側にある、値の見本。値の色そのもので塗った小さな正方形で、細い線で囲まれます。空のときは、その線だけです。コントロールではありません |
| 入力欄 | テキストとしての値。1 行で、収まらない分はスクロールします |
| ピッカーのボタン | `picker` を付けたとき。末尾側にあるアイコンだけのテキストボタンで、名前は `pickerLabel` です |
| 補足テキスト | 補足の 1 行。色見本を越えた、値のテキストが始まる位置から始まります。フィールドがエラーの間は、エラーテキストがその位置に代わって出ます（デザインシステムが両方を残す場合は、その下に）。`error` が true の間は `errorText`、確定したテキストが色でない間は `invalidText` で、`invalidText` が空のときは `errorText` です |

3 つのバリアントと、3 つのサイズ `small`（32）、`medium`（40）、`large`（56）は、テキストフィールドのものです。既定のシステムが提供するのは `stacked` だけです。色見本は、テキストフィールドの先頭のアイコンと同じ場所に、同じ大きさで置かれます。そのため、先頭にアイコンのあるテキストフィールドの下にカラーフィールドを置くと、先頭側の端がそろいます。

色見本には何も混ぜません。ホバーの色も、エラーの色も、影もありません。ポインターの下で変わる見本は、間違った見本です。無効のときは、塗りを薄く描き、縁はそのままにします。

### 値とテキスト

| いつ | 起きること |
| --- | --- |
| ユーザーが入力、貼り付け、音声入力をする | 拒否も書き直しもしません。テキスト全体を読みます。色であれば `value` はその色に、そうでなければ空になります。`value` が変わると `input` が発火します |
| フォーカスが離れる、または Enter | テキストを確定します。色は、値の書き方に書き直します。最後に確定した値と違っていれば `change` が発火します |
| 確定したテキストが色ではない | テキストは残ります。フィールドはエラーになって `invalidText` を表示し、`entryerror` が発火します。エラーは次の編集で終わります |
| テキストが空 | `value` は空になります。フィールドがそれをエラーにすることはありません |
| プロダクトが `value` を設定する | 入力されていた内容にかかわらず、その色を表示します。イベントは発火しません |

テキストは、前後の空白を除いて、ちょうど 6 桁の 16 進数であれば色として読みます。大文字でも小文字でも、番号記号があってもなくてもかまいません。`0F766E`、`#0f766e`、` #0F766E ` は、どれも `#0f766e` です。

それ以外はすべて、色ではありません。3 桁（`#0f7`）、8 桁（`#0f766e80`）、色の名前（`teal`）、関数の書き方（`rgb(15, 118, 110)`）などです。入力している間、3 桁は色になりません。6 桁を入力する途中でテキストが 3 桁を通るためです。テキストを確定すると、3 桁は CSS と同じく、各桁を重ねた 6 桁として読まれます（`#0f7` は `#00ff77` になります）。アルファも、広色域の色もありません。

ユーザーが入力している間は、何も報告しません。入力のエラーになるのは、確定したときだけです。

### ピッカー

`picker` を付けると、フィールドの末尾側にボタンが出ます。ボタンを押すと、値を伝える `pickerrequest` が発火します。

| プロダクト | 起きること |
| --- | --- |
| 何もしない | フィールドが、ブラウザーのカラーピッカーを表示します。選ぶたびに、ユーザーによる編集として扱います。テキスト、色見本、`input` です。ピッカーが閉じると `change` が発火し、フォーカスはピッカーのボタンにあります |
| 要求をキャンセルする | フィールドは何も表示しません。プロダクトが、フィールドをアンカーにしたプロダクト側のサーフェスを開き、選ばれた色を `value` に設定します。そのサーフェスは、閉じるときにフォーカスをピッカーのボタンに戻します |

ピッカーのボタンがあるときは、色見本を押すと、ボタンを押したときと同じくピッカーが開きます。入力欄にはフォーカスが移らず、キーボードで開く手段はボタンのままです。ボタンがないときは、フィールドのほかの場所を押したときと同じく、入力欄にフォーカスが移ります。

### それぞれの構成要素が受け持つもの

- **フィールドから**：プロパティの `label`、`labelHidden`、`supportingText`、`errorText`、`error`、`disabled`、`required`、`optional`、`requiredMark`、`requiredText`、`optionalText`。スロットの `label-icon`。トークンの `comp.field.*`。
- **カラー入力欄から**：プロパティの `variant`、`size`、`value`、`invalidText`、`picker`、`pickerLabel`。イベントの `input`、`change`、`pickerRequest`、`entryError`。トークンは、ボックスが `comp.input-box.*`（すべての入力ボックスが読みます）、スウォッチが `comp.color-input.*`。

カラー入力欄は、自身の `label`、`labelHidden`、`error`、`disabled` を持っています。カラーフィールドが設定するのは、これらではありません。カラーフィールドの `label` はフィールドのもので、入力欄に名前を与え、Filled と Outlined のフィールドではボックスの中で浮き上がります。

### トークン

カラーフィールドに自分のトークンはありません。ボックスは[カラー入力欄のトークン](https://tanrei.chnotchy.com/ja/components/color-input/#%E4%BB%95%E6%A7%98)を、行（ラベル、印、補足、エラー）は[フィールドのトークン](https://tanrei.chnotchy.com/ja/components/field/#%E4%BB%95%E6%A7%98)を、設定されている場所から読みます。下の表は、フィールドのトークンです。1 つのカラーフィールドだけを変えるには、構成要素のトークンをその要素に設定します。

```html
<tanrei-color-field label="ブランドカラー"
  style="--tanrei-comp-field-label-gap: 12px"></tanrei-color-field>
```

- Category: Text inputs
- Level: composed
- Listing: default
- Built from: Field, Color input
- Page: https://tanrei.chnotchy.com/components/color-field/
- Spec: https://github.com/chnotchy/tanrei/blob/main/specs/color-field.spec.json

### Availability

| Design system | Has it | Notes |
| --- | --- | --- |
| Tanrei (`tanrei`) | Yes | Variants left out: `filled`, `outlined`. |
| Cupertino (Apple HIG-inspired) (`cupertino`) | Yes | — |
| M3 Expressive-like (Material 3 Expressive-inspired) (`m3-expressive-like`) | Yes | — |
| M3-like (Material 3-inspired) (`m3-like`) | Yes | — |

### Platforms

- Web: the element `<tanrei-color-field>`, registered by importing `@tanrei/web` (or only its own module, `@tanrei/web/components/color-field`).
- React: `ColorField` from `@tanrei/react`.

| Platform | Name | Status |
| --- | --- | --- |
| Web | `tanrei-color-field` | lagging |
| SwiftUI | `TanreiColorField` | planned |
| Jetpack Compose | `TanreiColorField` | planned |
| Flutter | `TanreiColorField` | planned |
| React Native | `ColorField` | planned |

Names a platform gives in its own idiom:

| Spec | Web | SwiftUI | Jetpack Compose | Flutter | React Native |
| --- | --- | --- | --- | --- | --- |
| `value` (prop) | `value` | `hex` | `value` | `controller` | `value` |
| `label` (prop) | `label` | `label` | `label` | `labelText` | `label` |
| `labelHidden` (prop) | `labelHidden` | `labelsHidden` | `labelHidden` | `labelHidden` | `labelHidden` |
| `supportingText` (prop) | `supportingText` | `supportingText` | `supportingText` | `helperText` | `supportingText` |
| `error` (prop) | `error` | `error` | `isError` | `isError` | `error` |
| `disabled` (prop) | `disabled` | `disabled` | `enabled` | `enabled` | `disabled` |
| `required` (prop) | `required` | `isRequired` | `required` | `required` | `required` |
| `optional` (prop) | `optional` | `isOptional` | `optional` | `optional` | `optional` |
| `picker` (prop) | `picker` | `showsPicker` | `onPickerRequest` | `onPickerRequest` | `onPickerRequest` |
| `pickerLabel` (prop) | `pickerLabel` | `pickerLabel` | `pickerContentDescription` | `pickerSemanticLabel` | `pickerAccessibilityLabel` |
| `input` (event) | `input` | `hex` | `onValueChange` | `onChanged` | `onValueChange` |
| `change` (event) | `change` | `onCommit` | `onCommit` | `onCommit` | `onEndEditing` |
| `pickerRequest` (event) | `pickerrequest` | `onPickerRequest` | `onPickerRequest` | `onPickerRequest` | `onPickerRequest` |
| `entryError` (event) | `entryerror` | `onEntryError` | `onEntryError` | `onEntryError` | `onEntryError` |

Statuses: `planned` — In the inventory. Nothing shippable exists yet. `lagging` — An implementation of an earlier spec exists; it has not caught up with the current one. `alpha` — Implemented with tests. The API may still change. `beta` — Feature complete and at parity. Only fixes are expected. `stable` — Covered by semantic versioning. `deprecated` — Still shipped; scheduled for removal.

### Anatomy

- `field`: The Field: the label row with its glyph and its requirement mark, and the supporting row with the help and the error text. In a look whose input floats the label it draws no label row.
- `color-input`: The color input, as the Field's one control: the box, the swatch, the value as text, the picker button, and the label that floats in the box in the looks that float one.

### Props

| Prop | Type | Default | Web attribute | Description |
| --- | --- | --- | --- | --- |
| `variant` | `enum`: `stacked`, `filled`, `outlined` | `"stacked"` | `variant` | The text input's three looks, so that a color input is drawn as the text inputs beside it. Stacked is a filled box that shows focus and error with a line inside its edge and draws no label: the label of the Field that frames it stands above it. Filled and outlined float the label inside the box. Use one style per form. A design system may leave some out (the Tanrei system ships stacked only) or add values. (From Color input.) |
| `size` | `enum`: `small`, `medium`, `large` | `"medium"` | `size` | Minimum height of the container: stacked 32 / 40 / 56, as tall as a Button of the same size, so that the box and a Button side by side in one row stand as tall as each other; filled and outlined 40 / 48 / 56, which hold the label that floats inside them. These are the text input's three sizes, small for a bar, a toolbar or a dense row of controls. The hit area always meets the minimum target. A design system may add values. (From Color input.) |
| `value` | `string` | `""` | `value` | The color the input holds: a number sign and six hexadecimal digits in lowercase ("#0f766e"), an opaque sRGB color; or empty for no color. It is never a half-typed text: while the input holds something that is not a color, value is empty. (From Color input: What the color field reports as its own is the value its color input holds, in that value's own form (CLF-43, CLI-16, CLI-21).) |
| `label` | `string` | `""` | `label` | Names the control, visibly and to assistive technology. Required, unless the control names itself (a checkbox or a switch with its own label): then leave it empty and the field adds only help and an error. (From Field: Names the color input. In a filled or outlined look the input draws it, floating in its box, and the Field draws no label row (FLD-25, CLI-15).) |
| `labelHidden` | `boolean` | `false` | `label-hidden` | Does not draw the label, which stays the accessible name. For a control whose visible label is elsewhere (a table column, a toolbar). (From Field: Hides the label wherever it would be drawn: the Field's row, or the input's floating label (FLD-25).) |
| `supportingText` | `string` | `""` | `supporting-text` | Help shown below the control and given to assistive technology as the control's description. While the field is in error it gives way to errorText, unless the design system keeps both (comp.field.error-text.placement append). (From Field.) |
| `errorText` | `string` | `""` | `error-text` | Shown while error is true, in supportingText's place — or below it, which then stays, where the design system's comp.field.error-text.placement is append: what is wrong and how to put it right, in words. (From Field.) |
| `error` | `boolean` | `false` | `error` | Puts the field in the error condition: the error text is drawn, the control is exposed as invalid and, where it has an error condition of its own, drawn in it. What a value means is the product's to validate; the field never sets this itself. (From Field: The Field puts its color input in the input's own error condition (FLD-8, CLI-9).) |
| `disabled` | `boolean` | `false` | `disabled` | Disables the control and draws the frame as disabled. Disable a framed control here, not on the control, so that its label follows. (From Field: The Field disables its color input, the picker button with it (FLD-14, CLI-31); the color field is then left out of its form (CLF-44).) |
| `required` | `boolean` | `false` | `required` | What the form asks of the control: true exposes it as required and draws the required mark beside the label. It never validates: a missing answer is the product's to report with error. (From Field: The Field exposes its color input as required (FLD-10, CLI-11).) |
| `optional` | `boolean` | `false` | `optional` | Draws the optional tag after the label and adds optionalText to the control's description, because assistive technology has no state for it. Ignored while required is true: a control is never both. (From Field.) |
| `requiredMark` | `enum`: `auto`, `tag`, `asterisk`, `none` | `"auto"` | `required-mark` | How this control shows that it is required: tag is a small filled Tag with requiredText, asterisk is "*" after the label, none draws nothing and keeps the semantics. Auto takes comp.field.requirement.mark, which follows sys.behavior.requirement-mark, the system's one answer. Ignored unless required is true. (From Field.) |
| `requiredText` | `string` | `""` | `required-text` | The text of the required tag, in the product's language ("Required", "必須"). The product's: Tanrei has no word for it. Empty reads the product's words; with neither, FLD-24 says what is drawn. (From Field.) |
| `optionalText` | `string` | `""` | `optional-text` | The text of the optional tag, in the product's language ("Optional", "任意"); also read to assistive technology as part of the description. The product's: Tanrei has no word for it. Empty reads the product's words. (From Field.) |
| `invalidText` | `string` | `""` | `invalid-text` | The words for an input committed with a text that is not a color ("Enter six hexadecimal digits, like #0f766e"), in the product's language: given to the Field that frames the input, which shows them as its error text (CLI-20). While it is empty that Field shows its own errorText. (From Color input: Shown by the Field, in its supporting row (FLD-28).) |
| `picker` | `boolean` | `false` | `picker` | Shows the picker button. Activated, it emits pickerRequest, and where the platform has a color picker of its own the input presents that picker unless the product cancelled the request. The input draws no picker surface itself. (From Color input.) |
| `pickerLabel` | `string` | `""` | `picker-label` | The accessible name of the picker button ("Choose color"). Required while picker is shown. (From Color input.) |

### Events

| Event | Description |
| --- | --- |
| `input` | The person changed the value — by an edit of the text that made it a color, another color or no color, or by a pick in the platform's picker; carries the new value. Not emitted when the product sets value, nor for an edit that leaves value as it was. (From Color input.) |
| `change` | The person committed a changed value: focus left the input, the action key was pressed, or the platform's picker closed; carries the value. (From Color input.) |
| `pickerRequest` | The person activated the picker button; carries the value. Cancelling it keeps the input from presenting the platform's picker: the product then presents its own surface and sets value to what was picked. (From Color input.) |
| `entryError` | The person committed a text that is not empty and is not a color; carries the text as typed and invalidText, the words the input has for it (empty where the product gave none: the Field that frames the input then shows its own errorText). (From Color input.) |

### Slots

| Slot | Description |
| --- | --- |
| `label-icon` | A glyph before the label. (From Field.) |

### States

`enabled`, `disabled`, `hovered`, `focused`, `error`

### Accessibility

- Role: `textbox`
- Labeling: The color field adds nothing to what its members expose and coordinates nothing: the Field gives the color input its name, its description and its required, invalid and disabled states (FLD-8, FLD-10, FLD-11, FLD-14), and the color input carries them on its own element (CLI-11). Assistive technology meets one text box named by label whose value is the color as text, and, while picker is true, one button named by pickerLabel — exactly as it meets a Field around a color input written by hand.
- Minimum target size: yes

| Keys | Action |
| --- | --- |
| Every key | The color input's (its accessibility block; CLI-13, CLI-19, CLI-28). The color field handles no key and adds no focus stop (CLF-45). |

- One level down is the same thing: a Field with a color input in it. Every fixture has that pair as its twin, and the accessibility tree of the two is the same (CLF-43).
- On the web the two members stand in the color field's own shadow root, so the form meets the color field and not the input (CLF-44); focus passes through to the input (CLF-45).
- The color is never told by the swatch alone (WCAG 1.4.1), an error is always words (WCAG 3.3.1), and the swatch alone keeps its color in forced colors: each is the color input's or the Field's, and is said there (CLI-25, CLI-35, FLD-7, FLD-17).

### Behaviour

Requirements in EARS form, each with its stable id.

- **CLF-43** THE color field SHALL be a Field that frames one color input, and nothing else. It SHALL give label, labelHidden, supportingText, errorText, error, disabled, required, optional, requiredMark, requiredText and optionalText to its Field and variant, size, value, invalidText, picker and pickerLabel to its color input, each unchanged; SHALL hold the label-icon slot for its Field; and SHALL emit its color input's events as its own, each once. THE color field SHALL be as wide as the place it stands in, and its color input SHALL fill it: it is a block with no width of its own, as its Field is (FLD-1), around a control that fills the width it is given (CLI-44). Its value SHALL at every moment be the value its color input holds — a color in the value's own form, or the empty string (CLI-16) — and not the text the product set where the two differ (CLI-21). It SHALL draw no part of its own, hold no state of its own and have no token of its own: what it shows, how it behaves and what it exposes to assistive technology SHALL be exactly what that Field and that color input do when a product places the one in the other (FLD-1 to FLD-28; CLI-1 to CLI-44) — the label row and its requirement mark (FLD-2 to FLD-6), or the label that floats in the box with the Field's row left out (FLD-25, CLI-15, CLI-7); the supporting row, started at the value's text, after the swatch (FLD-7 to FLD-9, FLD-26, CLI-43); the name, the description and the states (FLD-10, FLD-11, FLD-14, CLI-11); and the entry error of a text that is not a color, shown in the Field's row (FLD-28, CLI-20).
- **CLF-44** WHERE the platform has forms (the web) THE color field SHALL be the one control the form sees: it SHALL take name, submit its color input's value, reset to the value it was first given, restore it on navigation, report to the form's constraint validation exactly what its color input would report there (CLI-11, CLI-20), and be left out WHILE disabled is true or a disabled group of the form holds it; its color input and its Field SHALL take no part in the form themselves. WHEN the action key asks for the form's submission (CLI-19) the form asked SHALL be the color field's own.
- **CLF-45** WHEN the color field is given focus — by the product, by a press on any part of it that FLD-12 or CLI-24 gives to the input, or by a form that reports its validity — THE color field SHALL pass the focus to the input of its color input, never to the picker button, and SHALL add no stop to the focus order: the stops inside it are its color input's, in that input's order (the input, then the picker button while it is shown, CLI-13). WHILE focus is anywhere inside it, the picker button included, THE color field SHALL count as focused for its Field, whose rows take their focused colors (FLD-13); the box takes its own only WHILE its input has focus (CLI-22). WHEN a picker the color input presented closes, focus SHALL be on the picker button (CLI-29), inside the color field.
- **CLF-46** IF the color field is placed in a Field THE color field SHALL in debug builds report that it is a field already and that the bare control is the color input, and both SHALL still render (FLD-15). WHILE it stands in a field group THE color field SHALL follow that group's disabled, through its own Field, and take nothing else from the group (FGR-20).
- **CLF-47** THE color field SHALL have no words of its own and SHALL read none: requiredText and optionalText are read by its Field (FLD-24), each from the instance's prop and then from the product's words; invalidText and pickerLabel are the instance's alone and are given to its color input as they are (CLI-42).
- **CLF-48** WHERE the platform has ARIA attributes (the web), WHEN the product sets an aria- attribute on the host, by the attribute or by the ARIA property that reflects it, THE color field SHALL move it to the data-aria- attribute of the same name, so that the host is no second node with its name, description or state, and SHALL expose it on the element that carries its role — an id reference by the elements it names in the host's tree or a tree around it, an error message as part of the description while the color field is invalid — except those the color field owns (aria-label, aria-labelledby, aria-disabled), which it SHALL move and not expose: its name is label (CLF-43). WHEN the product removes the aria- attribute or its data-aria- twin, or sets the ARIA property that reflects it (ariaLabel, ariaDescribedByElements…) to null, THE color field SHALL take it off that element. WHEN the product sets an aria- attribute the color field owns THE color field SHALL report it in debug builds.

### Tokens

As written in the token documents (DTCG): an alias in braces names the token it takes its value from, which each design system resolves. On the web each token is a CSS custom property: `--tanrei` and the name after `tanrei`, joined by hyphens (`tanrei.comp.field.…` → `--tanrei-comp-field-…`).

#### `tanrei.comp.field`

| Token | Type | Value |
| --- | --- | --- |
| `comp.field.label.typescale` | `typography` | `{tanrei.sys.typescale.label}` |
| `comp.field.label.gap` | `dimension` | `{tanrei.sys.space.space100}` |
| `comp.field.label-icon.size` | `dimension` | `{tanrei.sys.icon.small}` |
| `comp.field.label-icon.gap` | `dimension` | `{tanrei.sys.space.space100}` |
| `comp.field.requirement.mark` | `number` | `{tanrei.sys.behavior.requirement-mark}` |
| `comp.field.requirement.gap` | `dimension` | `{tanrei.sys.space.space100}` |
| `comp.field.requirement.asterisk-gap` | `dimension` | `{tanrei.sys.space.space25}` |
| `comp.field.supporting-text.typescale` | `typography` | `{tanrei.sys.typescale.label-small}` |
| `comp.field.supporting-text.gap` | `dimension` | `{tanrei.sys.space.space50}` |
| `comp.field.counter.gap` | `dimension` | `{tanrei.sys.space.space200}` |
| `comp.field.motion.state-duration` | `duration` | `{tanrei.sys.motion.role.state.default}` |
| `comp.field.motion.state-easing` | `cubicBezier` | `{tanrei.sys.motion.easing.state}` |
| `comp.field.standard.label.color` | `color` | `{tanrei.sys.color.on-surface}` |
| `comp.field.standard.label-icon.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.supporting-text.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.counter.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.required-asterisk.color` | `color` | `{tanrei.sys.color.primary}` |
| `comp.field.standard.error.label.color` | `color` | `{tanrei.sys.color.on-surface}` |
| `comp.field.standard.error.label-icon.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.error.supporting-text.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.error.counter.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.error.required-asterisk.color` | `color` | `{tanrei.sys.color.primary}` |
| `comp.field.standard.error.value-text.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.value-text.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field.standard.error-text.color` | `color` | `{tanrei.sys.color.error}` |
| `comp.field.value-text.typescale` | `typography` | `{tanrei.sys.typescale.label}` |
| `comp.field.value-text.gap` | `dimension` | `{tanrei.sys.space.space200}` |
| `comp.field.error-text.gap` | `dimension` | `{tanrei.sys.space.space50}` |
| `comp.field.error-text.placement` | `number` | `0` |

Per-state tokens, valued by the design system's pattern rules (not written by hand):

- `comp.field.<variant>.<state>.<property>` for the variants `standard`, the states `focused`, `disabled` and the properties `label.color`, `label-icon.color`, `supporting-text.color`, `required-asterisk.color`, `error.label.color`, `error.label-icon.color`, `error.supporting-text.color`, `error.required-asterisk.color`, `counter.color`, `error.counter.color`, `value-text.color`, `error.value-text.color`, `error-text.color`.

### Web での描き方の違い

- 要素のシャドウルートにあるのは、`<tanrei-color-input>` を入れた `<tanrei-field>` だけです。要素をインポートすると、両方が定義されます。
- カラーフィールドは、フォームに関連付けられる要素です。`name` を受け取り、`value` を送信します。色か、空文字列です。リセットでは `value` 属性に戻ります。`required` で `value` が空の間は値の欠落を、入力のエラーが続く間は不正な入力を、フォームに報告します。2 つの構成要素がフォームに項目を加えることはありません。
- `value` は、いつでもカラー入力欄のものです。`0F766E` と設定した値は `#0f766e` として、色ではない値は空文字列として読み返されます。
- `input` と `change` は `detail` のないイベントなので、`value` は要素から読みます。`pickerrequest` と `entryerror` は CustomEvent で、前者は `detail.value` を、後者は `detail.text` と `detail.message` を持ちます。どれもカラー入力欄自身のイベントで、ターゲットはこの要素です。`detail.message` は `invalidText` で、指定していなければ空です。フィールドが代わりに `errorText` を表示している間も空です。
- パーツ: `field` と `color-input` が 2 つの構成要素です。構成要素のパーツは、1 つ下の階層と同じ名前です。`label-icon`、`supporting-text` と、`container`、`outline`、`active-indicator`、`swatch`、`input`、`picker-button` です。`label` と `requirement-label` は、どちらの構成要素が描いていても、描かれているものを指します。`field-label`、`color-input-label`、`field-requirement-label`、`color-input-requirement-label` は、片方の構成要素のものを指します。
- 要素自体にはフォーカスが移らず、ロールもありません。`focus()` は入力欄に移り、ピッカーのボタンには移りません。ラベルの行、ボックス、色見本（ピッカーのボタンがないとき）、浮き上がるラベルを押すと、入力欄にフォーカスが移ります。補足やエラーテキストを押しても、何も起きません。
- ラベルと補足は、ピッカーのボタンを含め、フィールドの中のどこかにフォーカスがある間、フォーカス時の色になります。ボックスがフォーカス時の見た目になるのは、入力欄にフォーカスがある間だけです。
- 名前は `label` で付けます。ラベルを描かないときは `label-hidden` を付けます。`aria-label` は使いません。この要素では何の名前にもなりません。
- Tanrei は言葉を同梱しません。`requiredText` と `optionalText` は、指定するまで空です。`requiredText` のない必須のフィールドは、タグが置かれる場所にアスタリスクを表示します。
- ブラウザーのピッカーは、ブラウザーによって違います。Chromium ではページのポップアップ、Firefox と Safari ではシステムの色のウィンドウです。見た目、位置、キーは、ブラウザーのものです。
- 全角の文字で書いたテキスト（`＃０ｆ７６６ｅ`）は、色として読みません。
- 要素が定義されるまでは、大きさがありません。高さを確保してください。

## ガイドライン

### カラーフィールドとテキストフィールド

| 観点 | カラーフィールド | テキストフィールド |
| --- | --- | --- |
| 持つもの | 1 つの色。`#` と 6 桁 | 任意のテキスト |
| 見せるもの | テキストの横の色見本 | テキスト |
| 確かめること | テキストが色であること | なし |

表示するだけで編集しない色には、色見本を描き、その横に値か名前をテキストで添えます。カラーフィールドは、ユーザーが設定する色のためのものです。

### 推奨

- その色が何のためのものかが分かるラベルを書き、フォームでは見えるようにしておきます。
- 値の書き方は `supportingText` に書きます。補足はフィールドがエラーの間も残るので、`invalidText` で繰り返す必要はありません。
- 必要な場合は、色の名前を `supportingText` に言葉で書きます（「ティール」）。16 進数の値からは、色の見た目はほとんど分かりません。
- `picker` を付けるときは、必ず `pickerLabel` を指定します。
- 色の持つ意味は、利用者側で検証します。背景とのコントラストや、すでに使われている色かどうかなどです。結果は `error` と `errorText` で伝えます。
- パレットのトーンのように、行がそれぞれの色の名前をすでに示している場所では、[カラー入力欄](https://tanrei.chnotchy.com/ja/components/color-input/)を使います。ボックスだけの部品で、自身の `label` で名前を付けます。

### 非推奨

- 色を色見本だけで伝えない。値はテキストです。2 つの見本を見分けられないユーザーも、2 つの違う値を読めます。
- 空の `value` を、それだけでエラーとして扱わない。`required` は検証しません。
- ユーザーが入力している間に、`aria-invalid` や `error` を設定しない。`change` か `entryerror` を待ちます。
- カラーフィールドをフィールドの中に入れない。すでにフィールドです。フィールドが囲むコントロールは、[カラー入力欄](https://tanrei.chnotchy.com/ja/components/color-input/)です。

## アクセシビリティ

### コンポーネントが担うこと

- 入力欄はテキストフィールドです。名前は `label` で、描いても隠しても同じです。値は、表示しているテキストです。
- 表示している補足テキストまたはエラーテキストが説明になります。フィールドが任意の間は `optionalText` も加わります。
- `error` が true の間と入力のエラーが続く間は invalid として、`required` が設定されている間は必須として伝えます。
- フィールドにフォーカスがある間に現れたエラーは、1 回、控えめに読み上げます。フォーカスを奪うことはありません。
- 色見本は装飾で、支援技術からは隠します。色は、値のテキストが伝えます。
- ピッカーのボタンは、`pickerLabel` を名前とする別のボタンで、ダイアログを開くものとして伝えます。入力欄の次の、フォーカスが止まる位置です。フィールド自体に渡したフォーカスは、必ず入力欄に移ります。
- 値が変わっても何も読み上げず、フィールドが色の名前を加えることもありません。
- 入力メソッドが変換している間、フィールドは何も読まず、どのキーも扱いません。
- フィールドのヒット領域は最小ターゲットを満たし、ピッカーのボタンもターゲットを満たします。
- テキストを 200% にすると、ラベルと補足は折り返します。値は 1 行のままで、スクロールします。色見本の大きさは変わりません。
- 強制カラーモードでは、フィールドに縁が付き、ユーザーの色で描きます。色見本だけは値の色のままです。その色を見せることが、色見本の役目だからです。縁はテキストの色になります。
- 右から左のレイアウトでは、フィールドが反転します。色見本は右に、ピッカーのボタンは左に来ます。値そのものは左から右のままです。

Web での既知の制約：

- ブラウザーのピッカーは、Tanrei のものではありません。アクセシビリティは、ブラウザーのものです。
- 要素が定義されるまでは、何も描かれません。

### 利用者側で行うこと

- すべてのカラーフィールドに `label` を指定します。
- `invalidText` と `pickerLabel` は、ページの言語でフィールドに書きます。`requiredText` と `optionalText` は、フィールドに書くか、`setWords({ requiredText, optionalText })` でプロダクト全体に一度だけ渡します。[プロダクトの言葉](https://tanrei.chnotchy.com/ja/foundations/words/)を参照してください。
- 色は利用者側で検証して `error` を設定し、`errorText` には色の直し方を書きます。
- プロダクト側のピッカーを表示する場合は、ピッカーのボタンから開き、名前を付け、閉じるときにフォーカスをボタンに戻します。
