メインコンテンツへスキップ
menu palettetanreidark_modetranslate

カラーモード

コントラスト

デザインシステム

ギャラリーのシステムは、Tanrei でどこまで表現できるかを示すために、ほかのデザインシステムを模して作ったものです。サポート対象のデザインではなく、あくまで例です。

リンクをコピーテーマを編集
palettetanrei

カラーモード

コントラスト

デザインシステム

ギャラリーのシステムは、Tanrei でどこまで表現できるかを示すために、ほかのデザインシステムを模して作ったものです。サポート対象のデザインではなく、あくまで例です。

リンクをコピーテーマを編集
はじめにWebReactSwiftUIJetpack ComposeFlutterReact Nativeプリセット自分のデザインシステムを作るAI エージェントと Tanrei を使うブランドデザイントークンデザインシステムとカスタマイズTheme Studioカラータイポグラフィアイコン形状エレベーションモーションインタラクション状態振る舞いレイアウトサイズと密度アクセシビリティ言葉カラートークンタイプスケールトークン形状トークンエレベーショントークンモーショントークン状態トークンスペースと寸法のトークンコンポーネントボタンメインアクションボタンセグメントボタンcupertino, m3-like にありボタングループメニュー付きボタンツールバーコピーボタンチェックボックスラジオボタンスイッチチップメニュースライダースライダーフィールドカレンダーDateTimePickerフィールドグループラジオグループチェックボックスグループセレクトセレクトフィールドメニューバーファイルアップロードファイルピッカー 上級者向けドロップゾーンレーティングテキスト入力欄 上級者向けテキストフィールドチップフィールドフィールドコンボボックス 上級者向けコンボボックスフィールド数値入力欄 上級者向け数値フィールドカラー入力欄 上級者向けカラーフィールドワンタイムコード入力欄 上級者向けワンタイムコードフィールド埋め込みテキスト入力欄 上級者向けチャットコンポーザーカード区切り線モーダルレイヤー 上級者向けダイアログリストリスト行ボトムシートサイドシートカルーセルコードブロックテーブルポップオーバーステップアコーディオン説明リスト図アプリシェルページヘッダーツリービュータイムライン画像プレビューハンドルサイズ変更できる枠分割ビュースクロールエリアサイズトランジションバッジプログレスインジケーターメーターナンバーティッカーローディングインジケータースナックバーツールチップキーボードショートカットタグインラインコードコールアウトアバター空の状態タググループスケルトンファイル項目色見本マーキーテキストタブタブビューアプリバーナビゲーションバーナビゲーションドロワー検索リンクページネーション前後のリンクステッパーパンくずリスト目次リンクカードFAB メニューm3-like にありステータスTanrei の作り方コントリビューションライセンスと帰属
ホームコンポーネントレーティング

レーティング

星などいくつかの印で点数を付けてもらう、または付いた点数を示します。点数は印 1 つ単位で、プロダクトが許せば半分単位で扱います。

content_copyMarkdown で表示
カテゴリ
選択
トークン
comp.rating
レベル
基礎

概要

Web
tanrei-rating
clock_loader_40
SwiftUI
TanreiRating
radio_button_unchecked
Jetpack Compose
TanreiRating
radio_button_unchecked
Flutter
TanreiRating
radio_button_unchecked
React Native
Rating
radio_button_unchecked

生成元 docs/status/status.json, specs/rating.spec.json

付ける点数と、読むだけの平均点

使い方

Web と React の例は現在の仕様に沿っています。SwiftUI、Compose、Flutter、React Native は予定で、まだレーティングを提供していません。

<tanrei-rating name="score" label="このレシピの評価"></tanrei-rating>

<!-- 各点数の言葉は、プロダクトの言語で。ポインターを置いている間、レーティングの横に出します。 -->
<tanrei-rating
  label="あなたの評価"
  option-labels='["悪い", "まあまあ", "良い", "とても良い", "最高"]'
></tanrei-rating>
<span id="words"></span>

<!-- 読むだけの平均点。 -->
<tanrei-rating label="平均評価" value="4.5" read-only value-text="5 つ星中 4.5"></tanrei-rating>

<script type="module">
  import '@tanrei/web/components/rating';
  const rating = document.querySelector('tanrei-rating[option-labels]');
  rating.addEventListener('change', (event) => save(event.detail.value));
  rating.addEventListener('preview', (event) => {
    const score = event.detail.value ?? rating.value;
    document.querySelector('#words').textContent = score ? rating.optionLabels[score - 1] : '';
  });
</script>
import { Rating } from '@tanrei/react';

<Rating label="このレシピの評価" value={score} onChange={(event) => setScore(event.detail.value)} />
<Rating
  label="あなたの評価"
  optionLabels={['悪い', 'まあまあ', '良い', 'とても良い', '最高']}
  onPreview={(event) => setPointed(event.detail.value)}
/>
<Rating label="平均評価" value={average} readOnly valueText={`5 つ星中 ${average}`} />

仕様

サイズ:Small、Medium、Large

半分単位、別のグリフ、10 個の印、無効

構成要素

構成要素

Web パッケージが描くフィクスチャ empty の上に描いています。
パーツ 説明
1 container The round area behind each mark that carries hover, focus and press: the state layer is drawn on it. One per mark, side by side with no space between them.
2 mark The glyph of one step of the score (star by default), drawn filled while it is within the value and outlined while it is not; a half value draws its last mark filled on its start half only.
3 focus-ring Gap-then-ring indicator around the focused mark's container (around every mark while the rating is a slider, RAT-4).

寸法

寸法

長さ トークン 値(px)
container size tanrei.comp.rating.container.size.medium 32
mark size tanrei.comp.rating.mark.size.medium 24
Web パッケージが描くフィクスチャ empty の上に描いています。

プロパティ

プロパティ 型 既定値 説明
value number 0 The score: a number of marks from 0 to max, in whole marks or, while allowHalf is true, in halves. 0 is no score yet.
max number 5 How many marks are drawn: the highest score. A whole number from 1.
allowHalf boolean false Lets a person give a score that ends on a half mark: a press on the start half of a mark gives that mark less a half, and the arrow keys move by a half. A read-only rating shows halves whatever it says (RAT-14).
size small | medium | large "medium" The size of each mark (20 / 24 / 32) and of the round area behind it (28 / 32 / 40). The hit area always meets the minimum target. A design system may add values.
icon string "" The name of the glyph of one mark in the system's icon set (favorite, thumb_up); empty draws star. One glyph for every mark; the filled and the outlined forms are the icon set's two fills.
label string "" Names the rating for assistive technology ("Your rating of this recipe"). Required. Never drawn: a visible question beside the rating is the product's, and uses the same words.
optionLabels strings The name of each score a person can give, in ascending order from the lowest (one mark, or a half mark while allowHalf is true): ["Poor", "Fair", "Good", "Very good", "Excellent"]. Empty names each score by its number, written as the platform writes a number in the language of the element.
valueText string "" How assistive technology reads a read-only rating's score ("4.5 out of 5 stars"), in the product's language. Empty reads the score's name from optionLabels, or its number.
readOnly boolean false Shows a score that cannot be changed — an average, a review's score — as one image with a name: not focusable and not pressable.
disabled boolean false Shows the rating as unavailable: drawn in the disabled colors, not focusable, taking no input and left out of form submission.

イベント

イベント 説明
change The person changed the score: a press on a mark or a key. Carries the new value. Not emitted when the product sets value.
preview A fine pointer moved onto a mark, or off the rating: carries the score the pointer would give, or null when it leaves, so that the product can show that score's words while the person points ("Very good").

状態

振る舞い

EARS 記法による要件です。各プラットフォームの実装は、この ID に対応するテストで検証されます。要件の原文は仕様ファイルのものをそのまま掲載しています。

ID 要件
RAT-1 THE rating SHALL draw max marks in a row from its inline-start edge, each the glyph icon names (star WHILE icon is empty) at comp.rating.mark.size.medium for size medium (and so on for each size), centred in a round container comp.rating.container.size.medium across (and so on), with the containers touching: the marks within value SHALL be drawn from the selected condition — sys.icon.family.selected, sys.icon.fill.selected and comp.rating.selected.mark.color — and the others from the unselected condition — sys.icon.family.unselected, sys.icon.fill.unselected and comp.rating.unselected.mark.color — with sys.icon.weight and an optical size clamped between sys.icon.optical-size.min and sys.icon.optical-size.max.
RAT-2 WHILE value ends on a half mark THE rating SHALL draw that mark twice in its place — from the selected condition clipped to its inline-start half and from the unselected condition clipped to its inline-end half, divided at the glyph's centre line — so that one mark reads as half filled, its filled half on the right WHERE the layout direction is right-to-left.
RAT-3 WHILE readOnly is false, disabled is false, allowHalf is false and max is at most 7 THE rating SHALL be a radio group named by label, each mark a radio named by its entry in optionLabels or, WHILE optionLabels has no entry for it, by its score written as the platform writes a number in the language of the element, checked WHILE its score equals value, with one stop in the focus order: the checked mark, or the first mark WHILE value is 0; THE rating SHALL answer the keys as a radio group does (RGP-5, RGP-6) — Right Arrow and Down Arrow check the next mark, Left Arrow and Up Arrow the previous one, both wrapping, Left and Right exchanged WHERE the layout direction is right-to-left, Space checks the focused mark — and emit change once for each change of value.
RAT-4 WHILE readOnly is false, disabled is false, and allowHalf is true or max is above 7 THE rating SHALL be one slider named by label, from 0 to max, with value as its current value and as its value text the entry of optionLabels for value or, WHILE there is none, nothing, so that the platform reads the number; it SHALL be one stop in the focus order and SHALL answer the keys as a slider does: Right Arrow and Up Arrow raise the value by one step — a half while allowHalf is true, a whole mark otherwise — and Left Arrow and Down Arrow lower it, never below one step and never above max (Right and Left exchanged WHERE the layout direction is right-to-left), Page Up and Page Down by one whole mark, Home to one step and End to max, and emit change once for each change of value.
RAT-5 WHILE readOnly is true and disabled is false THE rating SHALL draw its value as RAT-1 and RAT-2 say, SHALL take no press, no key and no focus, and SHALL expose itself as one image named by label and described by valueText or, WHILE valueText is empty, by the entry of optionLabels for value or else value written as the platform writes a number in the language of the element; WHILE value is 0 it SHALL be described as such by valueText alone, and in debug builds SHALL report a read-only rating with neither valueText nor a value above 0.
RAT-6 WHEN the user presses a mark by pointer or touch, or Space on a focused mark (RAT-3), WHILE readOnly and disabled are false THE rating SHALL set value to that mark's score — to that mark less a half WHILE allowHalf is true and the press lands on the mark's inline-start half — and WHEN that differs from value emit change once with the new value; a press on the mark of the score already given SHALL change nothing, so that no input takes a score back to 0.
RAT-7 WHILE a fine pointer is over a mark and readOnly and disabled are false THE rating SHALL draw every mark as RAT-1 and RAT-2 would draw them for the score the pointer would give (RAT-6), with that mark's container in its hovered state, and emit preview with that score each time it changes; WHEN the pointer leaves the rating THE rating SHALL draw its value again and emit preview once with null.
RAT-8 WHERE a mark's container is below the minimum target THE rating SHALL extend that mark's hit area on both axes to sys.target.touch for touch input and sys.target.pointer for fine pointers, without changing its visual size; a platform that cannot tell the input type SHALL use sys.target.touch; WHERE the hit areas of neighbouring marks overlap, a point SHALL belong to the mark whose centre is nearer, so that the row is divided at the middle between marks.
RAT-9 WHEN a mark is pressed by pointer, touch or Space THE rating SHALL show the pressed state on that mark's container without delay and SHALL keep it visible for at least sys.motion.duration.press-hold, even when the press ends sooner.
RAT-10 WHILE pressed THE rating SHALL answer as sys.behavior.pressed-feedback names: overlay applies the pressed tokens to the whole container at once; ripple grows the pressed state layer from the point of contact (from the center for keyboard activation); dim applies the pressed opacity to the whole control and draws no state layer; none draws no answer to the press. Under ripple and dim only the container color stays with the state under the press; mark, opacity and shape still come from the pressed tokens. Under none every part stays with the state under the press. The ripple grows over comp.rating.motion.feedback-duration with motion.state-easing, fades over motion.state-duration with motion.state-easing once the press has ended and press-hold has passed, and appears whole where motion is reduced.
RAT-11 THE rating SHALL ease its container corners by sys.shape.corner-smoothing (0 is a quarter circle, 0.6 the iOS continuous corner; a platform with only the OS curve draws it for any amount above 0) and show its keyboard focus as sys.behavior.focus-style names (ring or glow) — around the focused mark's container while it is a radio group, around the row of containers while it is a slider — at sys.focus.offset, never for focus gained by pointer; a platform that cannot draw a choice SHALL fall back to the first value and state that in its README.
RAT-12 WHEN value changes THE rating SHALL change each mark between its unselected and its selected form over comp.rating.motion.selection-duration with comp.rating.motion.selection-easing, as a fade between the two forms, going on from the form then shown WHEN it changes again during the motion (MOT-2), and SHALL change its containers' state colors over comp.rating.motion.state-duration with comp.rating.motion.state-easing; THE rating SHALL draw its first frame at its value without a motion (MOT-3), and WHERE motion is reduced the fades stay (MOT-6).
RAT-13 WHILE disabled is true THE rating SHALL render its containers and marks from the disabled tokens of each mark's condition, SHALL NOT be focusable or take any input, SHALL emit nothing, SHALL expose its disabled state and its value to assistive technology, and SHALL be left out of form submission.
RAT-14 WHEN the product sets value THE rating SHALL draw the new value and SHALL NOT emit change; IF value is below 0 or above max THE rating SHALL draw and expose it clamped to that range, and IF it is not a multiple of a half, or not a whole number while allowHalf is false and the rating is not read-only, SHALL draw and expose the nearest score it can show — a read-only rating shows halves whatever allowHalf says, so that an average is drawn to the nearest half; IF max is not a whole number from 1 THE rating SHALL take the whole number below it and at least 1; in each case debug builds SHALL report the value.
RAT-15 WHERE the platform has forms (the web) THE rating SHALL take part in them as a native control does: it takes name, submits value WHILE it is above 0 and nothing WHILE it is 0, restores it on navigation and resets to the value it was first given, and Enter while it has focus submits its form as Enter in a native radio does; WHILE readOnly is true it SHALL submit its value, and WHILE disabled is true nothing.
RAT-16 WHERE the layout direction is right-to-left THE rating SHALL draw its first mark at the right, the score growing leftward, and SHALL draw the glyph mirrored as RAT-19 says; it SHALL take its layout direction from where it is used and have no direction setting of its own.
RAT-17 WHERE the platform draws with a person's own forced colors THE rating SHALL draw every mark in the platform's text color — the selected form filled and the unselected form outlined, so that the score is read from the shapes and not from a color — the hovered mark's container in the platform's highlight color, and a disabled rating in the platform's disabled text color.
RAT-18 WHILE label is empty THE rating SHALL still render and in debug builds report that it has no accessible name; WHILE optionLabels is not empty and does not hold exactly one entry for each score a person can give THE rating SHALL use the entries it has, name the others by their numbers, and in debug builds report the count; WHEN size names a value the active design system does not have THE rating SHALL render with medium's tokens and in debug builds report the unknown value; WHILE icon names no glyph of the system's icon set THE rating SHALL draw star and in debug builds report the name.
RAT-19 WHERE the layout direction is right-to-left THE rating SHALL draw the glyph of its marks mirrored left to right exactly when the system's icon set marks that glyph's name as mirrored or — for the glyph icon names — the product forces mirroring for that use, and unmirrored when the product forbids it: the icon helper mirrors the glyph inside each mark's box, about the box's vertical centre line, changing neither the marks' places, sizes and colors nor the halves RAT-2 draws. The star the rating draws while icon is empty is its own glyph and takes no word of the product's. THE rating SHALL NOT mirror a mark itself.
RAT-20 WHEN the control height (dial.control.height) changes THE rating SHALL keep its own size: a mark's container (comp.rating.container.size.medium, and so on for each size) is the pitch of a row of glyphs, which follows the size of its mark (comp.rating.mark.size.medium, and so on), and no control of a row's height, so THE rating SHALL draw its containers and marks at their own sizes at every control height; a person's reach is the hit area's, which SHALL still meet the minimum target around each mark (RAT-8), not a wider pitch between the marks.

プラットフォーム別の名前対応

パリティは API が同一であることを意味しません。同じ契約を、各プラットフォームの流儀で表現します。

仕様 Web SwiftUI Jetpack Compose Flutter React Native
コンポーネント tanrei-rating TanreiRating TanreiRating TanreiRating Rating
value · プロパティ value value value value value
max · プロパティ max maximum max max max
allowHalf · プロパティ allowHalf allowsHalf allowHalf allowHalf allowHalf
size · プロパティ size size size size size
icon · プロパティ icon systemImage icon icon icon
label · プロパティ label label label label label
optionLabels · プロパティ optionLabels optionLabels optionLabels optionLabels optionLabels
valueText · プロパティ valueText valueText valueText valueText valueText
readOnly · プロパティ readOnly isReadOnly readOnly readOnly readOnly
disabled · プロパティ disabled .disabled(_:) enabled enabled disabled
change · イベント change value (Binding) onValueChange onChanged onValueChange
preview · イベント preview onPreview onPreview onPreview onPreview
備考 Form-associated. As a radio group, the shadow root holds one element with role="radiogroup" and aria-label, and one role="radio" element per mark with a roving tabindex — not <input type="radio">, whose name group cannot span shadow roots; as a slider, one role="slider" element with aria-valuemin="0", aria-valuemax, aria-valuenow and aria-valuetext while an entry names the value; read-only, one role="img" element with aria-label and aria-description. optionLabels is an array property whose attribute option-labels is read as a JSON array. allow-half, read-only, value-text are the attributes. A half mark is two glyphs in one box, each clipped with clip-path: inset() on its half, the halves swapped in right-to-left. change and preview are CustomEvents whose detail.value is the score (null for preview's leaving). Every mark carries the container part and its glyphs the mark part. data-mirror (auto, the default; always; never) on the rating is the product's word on mirroring the glyph icon names (RAT-19), as on a glyph the product places itself; the star drawn while icon is empty takes none. TanreiRating("Your rating", value: $score). Exposed as one adjustable element (accessibilityAdjustableAction) in every mode, because VoiceOver has no radio group: swipe up and down move by a step; the radio-group mode's semantics apply where a platform has them. Radio-group mode: Modifier.selectableGroup() with each mark selectable(role = Role.RadioButton); slider mode: progressSemantics with setProgress; read-only: Role.Image with the description. enabled is the inverse of disabled. Radio-group mode: each mark Semantics(inMutuallyExclusiveGroup: true, checked:); slider mode: Semantics(slider: true, value:, increasedValue:, decreasedValue:); read-only: Semantics(image: true). A null onChanged is disabled. Radio-group mode: accessibilityRole="radiogroup" with each mark role="radio" and accessibilityState.checked; slider mode: accessibilityRole="adjustable" with accessibilityActions increment and decrement; read-only: accessibilityRole="image".

トークン

トークン 参照先 解決値(ライト)
--tanrei-comp-rating-container-shape sys.shape.corner.full 9999px
--tanrei-comp-rating-container-size-large — 40px
--tanrei-comp-rating-container-size-medium — 32px
--tanrei-comp-rating-container-size-small — 28px
--tanrei-comp-rating-disabled-container-shape — 9999px
--tanrei-comp-rating-disabled-opacity — 1
--tanrei-comp-rating-focused-container-shape — 9999px
--tanrei-comp-rating-focused-opacity — 1
--tanrei-comp-rating-hovered-container-shape — 9999px
--tanrei-comp-rating-hovered-opacity — 1
--tanrei-comp-rating-mark-size-large sys.icon.large 32px
--tanrei-comp-rating-mark-size-medium sys.icon.medium 24px
--tanrei-comp-rating-mark-size-small sys.icon.small 20px
--tanrei-comp-rating-motion-feedback-duration sys.motion.role.feedback 450ms
--tanrei-comp-rating-motion-selection-duration sys.motion.role.selection.mark 250ms
--tanrei-comp-rating-motion-selection-easing sys.motion.easing.state cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-rating-motion-state-duration sys.motion.role.state.compact 200ms
--tanrei-comp-rating-motion-state-easing sys.motion.easing.state cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-rating-pressed-container-shape — 9999px
--tanrei-comp-rating-pressed-opacity — 1
--tanrei-comp-rating-selected-container-color — #000000 · 0%
--tanrei-comp-rating-selected-disabled-container-color — #000000 · 0%
--tanrei-comp-rating-selected-disabled-mark-color — #1b1b1b · 38%
--tanrei-comp-rating-selected-disabled-state-layer-color — #1b1b1b · 38%
--tanrei-comp-rating-selected-focused-container-color — #1b1b1b · 10%
--tanrei-comp-rating-selected-focused-mark-color — #1b1b1b
--tanrei-comp-rating-selected-focused-state-layer-color — #1b1b1b
--tanrei-comp-rating-selected-hovered-container-color — #1b1b1b · 8%
--tanrei-comp-rating-selected-hovered-mark-color — #1b1b1b
--tanrei-comp-rating-selected-hovered-state-layer-color — #1b1b1b
--tanrei-comp-rating-selected-mark-color sys.color.primary #1b1b1b
--tanrei-comp-rating-selected-pressed-container-color — #1b1b1b · 10%
--tanrei-comp-rating-selected-pressed-mark-color — #1b1b1b
--tanrei-comp-rating-selected-pressed-state-layer-color — #1b1b1b
--tanrei-comp-rating-selected-state-layer-color comp.rating.selected.mark.color #1b1b1b
--tanrei-comp-rating-unselected-container-color — #000000 · 0%
--tanrei-comp-rating-unselected-disabled-container-color — #000000 · 0%
--tanrei-comp-rating-unselected-disabled-mark-color — #1b1b1b · 38%
--tanrei-comp-rating-unselected-disabled-state-layer-color — #1b1b1b · 38%
--tanrei-comp-rating-unselected-focused-container-color — #848484 · 10%
--tanrei-comp-rating-unselected-focused-mark-color — #848484
--tanrei-comp-rating-unselected-focused-state-layer-color — #848484
--tanrei-comp-rating-unselected-hovered-container-color — #848484 · 8%
--tanrei-comp-rating-unselected-hovered-mark-color — #848484
--tanrei-comp-rating-unselected-hovered-state-layer-color — #848484
--tanrei-comp-rating-unselected-mark-color sys.color.outline #848484
--tanrei-comp-rating-unselected-pressed-container-color — #848484 · 10%
--tanrei-comp-rating-unselected-pressed-mark-color — #848484
--tanrei-comp-rating-unselected-pressed-state-layer-color — #848484
--tanrei-comp-rating-unselected-state-layer-color comp.rating.unselected.mark.color #848484

フィクスチャ

基準となる描画パターンです。全プラットフォームが同じ ID でスナップショットを撮り、結果を比較できるようにしています。

生成元 specs/rating.spec.json, tokens/comp/rating.tokens.json, design/tokens/

ガイドライン

使う場面

レシピ、商品、宿泊のレビューのように、短い尺度で点数を付けてもらうときに使います。一覧に並べた商品のレビューの平均点のように、付いた点数を示すときにも使います。印の並びがそのまま尺度になるので、印がいくつあり、いくつ付いているかがひと目でわかります。

選択肢が 1 つの尺度の段階ではなく言葉であるなら、ラジオグループを使います。長い範囲や連続した範囲の値にはスライダーを使います。

印 1 つ単位と半分単位

設定 付けられる点数 支援技術から見えるもの
印 1 つ単位、7 個まで 印ごとに 1 つの点数 ラジオグループ。印ごとに 1 つのラジオで、矢印キーで次または前の印を選びます
半分単位、または 8 個以上 最大値までの半分ごと(または印ごと)の点数 スライダー。矢印キーで 1 段階、Page Up と Page Down で印 1 つ、Home と End で両端に動きます
読み取り専用 なし 1 枚の画像。ラベルが名前、値のテキストが説明になります

半分単位は、その細かさが必要な場合にだけ許可します。5 つ星を半分単位にすると選択肢は 10 になり、付けるのに時間がかかります。読み取り専用のレーティングは常に半分単位で描くので、4.3 のような平均点は 4 つ半の印になります。正確な値は値のテキストで伝えます。

サイズの選び方

サイズ 既定のシステムでの印 / 丸い領域 用途
Small 20 / 28 一覧の行、小さなテキストの横。
Medium 24 / 32 フォーム。既定値です。
Large 32 / 40 商品のページのように、その画面の主役である点数。

どのサイズでも、各印はタッチターゲットを丸ごと持ちます。隣り合う印は、その間の領域を真ん中で分け合います。

点数を取り消す

レーティングには、付けた点数をなしに戻す操作がありません。ポインターでも、キーでも、支援技術でもできません。付いている点数の印を押しても何も変わりません。ラジオグループに選択を外す操作がないのと同じです。点数を取り下げられるようにする必要があるフォームでは、レーティングの横に、値を 0 にする Text のボタンを置きます。

推奨

  • 何を評価するのかがわかるラベルを付けます。「このレシピの評価」のようにします。横に質問を表示するなら、同じ言葉を使います。
  • 段階に意味があるなら(「悪い」「最高」)、optionLabels で各点数にプロダクトの言語で名前を付けます。ポインターを置いている間は、その言葉をレーティングの横に出します(preview)。
  • 読み取り専用のレーティングには、点数を正確に伝える値のテキストを付けます。「5 つ星中 4.3、レビュー 128 件」のようにします。

非推奨

  • 1 つの尺度の段階ではない選択肢に、レーティングを使わない。
  • 星の色だけに頼らない。既定のシステムは、付いた印を塗りつぶし、それ以外を線で描くので、点数は形から読めます。色を変えるときも、この違いは残します。
  • ひと目で数えられないほど多くの印を使わない。読みやすいのは 10 個までです。

アクセシビリティ

フォーカス順

番号は Tab で止まる位置で、Tab で進む順に振っています。Shift+Tab では同じ順に戻ります。コンポーネントは実際に動くので、Tab を押してたどれます。 Web パッケージが描くフィクスチャ value の上に描いています。
    ロール
    radiogroup of radios (whole marks, up to 7); slider (half marks, or more than 7 marks); img (read-only)
    ラベル付け
    label names the radio group, the slider or the read-only image. Each radio is named by its entry in optionLabels or by its number; the slider's value text is the entry for its value, or the platform reads the number. A read-only rating is described by valueText. The marks' glyphs are decorative.
    最小ターゲット
    見た目のサイズが小さくても、ヒット領域は最小ターゲットサイズを満たします。 minimum 36px · pointer 36px · spacing 8px · touch 36px

    キーボード操作

    キー 動作
    Tab または Shift Tab Moves focus to the rating — to the checked mark, or to the first mark while there is no score — and out of it. One stop.
    右矢印 または 下矢印 (radio group) Checks the next mark, wrapping from the last to the first; Left Arrow in a right-to-left layout.
    左矢印 または 上矢印 (radio group) Checks the previous mark, wrapping from the first to the last; Right Arrow in a right-to-left layout.
    Space (radio group) Checks the focused mark when none is checked. A press on the checked mark changes nothing: a score is never taken back to none.
    右矢印 または 上矢印 または 左矢印 または 下矢印 (slider) Raises or lowers the score by one step (a half where halves are allowed), between one step and max.
    Page Up または Page Down (slider) Raises or lowers the score by one whole mark.
    Home または End (slider) Sets the lowest score (one step) or the highest (max).
    Enter Submits the form the rating stands in, as in a native radio; it sets no score.

    備考

    • WAI-ARIA APG: a radio group suits up to seven choices; with more, a slider's keys make choosing faster (the Rating Slider example). Five whole stars are five radios (the Rating Radio Group example); five stars in halves are ten choices, so the rating is a slider (RAT-3, RAT-4).
    • There is no way to take a score back to none once given, by any input, as there is none in a radio group. A product whose form needs it places a Button beside the rating that sets value to 0.
    • The unselected mark is drawn in comp.rating.unselected.mark.color, outline in the default system: a functional boundary of at least 3:1 against the surface, so that the marks not given can be counted (WCAG 1.4.11). The filled and outlined forms differ in shape as well as color (WCAG 1.4.1).
    • Neighbouring marks share their extended hit areas by distance (RAT-8): at size medium each mark has 32 of the row's width, above the 24 that WCAG 2.5.8 asks.

    生成元 specs/rating.spec.json, tokens/sys/measure.tokens.json

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

    • 印 1 つ単位で 7 個までなら、ラベルを名前とするラジオグループになります。各印は、optionLabels の項目、またはページの言語で書いた数を名前とするラジオです。フォーカスが止まる位置は 1 つで、選ばれている印、点数がなければ最初の印です。矢印キーで次または前の印を選び、端では反対側に回ります。Space でフォーカスのある印を選び、Enter でフォームを送信します。
    • 半分単位、または 8 個以上なら、0 から最大値までの 1 つのスライダーになります。値のテキストは、その点数に当たる optionLabels の項目です。矢印キーで 1 段階、Page Up と Page Down で印 1 つ、Home で 1 段階、End で最大値に動きます。
    • 読み取り専用なら、ラベルを名前とし、値のテキストで説明される 1 枚の画像になります。フォーカスも押すこともできません。
    • 各印のヒット領域は、描かれるものを変えずに最小ターゲットまで広がります。隣り合う印は、その間の真ん中で分かれます。
    • 点数の内側の印は塗りつぶし、それ以外は線で描くので、点数が色だけに頼ることはありません。線の印はサーフェスに対して 3:1 を保ちます。強制カラーモードでは、すべての印をテキストの色で描きます。
    • 無効のときは無効の色で描き、フォーカスできず、入力を受け付けず、フォームから外れます。点数は伝え続けます。
    • 空のラベル、長さの合わない optionLabels、描けない値、未知のサイズ、説明のない読み取り専用のレーティングは、デバッグビルドで報告します。

    利用者側で行うこと

    • すべてのレーティングにラベルを、読み取り専用のものには値のテキストを付けます。
    • optionLabels と valueText の言葉は、プロダクトの言語で書きます。
    • 点数を取り下げられるようにするなら、そのためのボタンを用意します。レーティングには取り消す操作がありません。