ナビゲーション

v2.1.0
フォーム

尺度

尺度の両端の間に並ぶ数値から 1 つを選んで回答。

このページの内容

尺度は、両端の間に並ぶ数値から 1 つを選び、可能性や満足度、難しさなどの程度を答えるコンポーネントです。各数値は、ネイティブのラジオボタンを囲む<label>内に表示します。矢印キーで選択肢を移動でき、選んだ値はフォームで扱えます。通常時のセルは輪郭線のある平らな面で、選択したセルはインク色で示します。

尺度

<div class="card w-full max-w(480)">  <fieldset class="fieldset">    <legend class="fieldset-legend">How likely are you to recommend Atlas to a colleague?</legend>    <div class="scale">      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="0">0      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="1">1      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="2">2      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="3">3      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="4">4      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="5">5      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="6">6      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="7">7      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="8" checked>8      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="9">9      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="10">10      </label>      <p class="scale-ends"><span>Not at all likely</span><span>Extremely likely</span></p>    </div>  </fieldset></div>
<div className="card w-full max-w(480)">  <fieldset className="fieldset">    <legend className="fieldset-legend">      How likely are you to recommend Atlas to a colleague?    </legend>    <div className="scale">      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="0" />0      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="1" />1      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="2" />2      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="3" />3      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="4" />4      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="5" />5      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="6" />6      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="7" />7      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="8" defaultChecked />8      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="9" />9      </label>      <label className="scale-option">        <input className="scale-input" type="radio" name="recommend" value="10" />10      </label>      <p className="scale-ends"><span>Not at all likely</span><span>Extremely likely</span></p>    </div>  </fieldset></div>
<div class="card w-full max-w(480)">  <fieldset class="fieldset">    <legend class="fieldset-legend">How likely are you to recommend Atlas to a colleague?</legend>    <div class="scale">      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="0">0      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="1">1      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="2">2      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="3">3      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="4">4      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="5">5      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="6">6      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="7">7      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="8" checked>8      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="9">9      </label>      <label class="scale-option">        <input class="scale-input" type="radio" name="recommend" value="10">10      </label>      <p class="scale-ends"><span>Not at all likely</span><span>Extremely likely</span></p>    </div>  </fieldset></div>
<template>  <div class="card w-full max-w(480)">    <fieldset class="fieldset">      <legend class="fieldset-legend">How likely are you to recommend Atlas to a colleague?</legend>      <div class="scale">        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="0">0        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="1">1        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="2">2        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="3">3        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="4">4        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="5">5        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="6">6        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="7">7        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="8" checked>8        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="9">9        </label>        <label class="scale-option">          <input class="scale-input" type="radio" name="recommend" value="10">10        </label>        <p class="scale-ends"><span>Not at all likely</span><span>Extremely likely</span></p>      </div>    </fieldset>  </div></template>

#数値の行と両端のラベル

セルは 4px 間隔で行の幅を均等に分け合うため、数値が 5 個でも 11 個でも、割り当てられた列の幅いっぱいに広がります。セルの高さはボタンと同じ 38px で、周囲の入力欄とそろいます。セルの幅は最低 28px で、行に収まりきらない場合は 2 行目に折り返します。

数値だけでは、その意味は伝わりません。scale-endsは数値の行の下に置く、尺度の両端のラベルを並べた行です。尺度の中で、最後のセルの後に置きます。質問文は、上の例のようにフィールドセットの凡例に置くか、role="radiogroup"を指定した尺度のaria-labelに記述します。

5 段階

<div class="scale w-full max-w(280)" role="radiogroup" aria-label="How hard was it to set up?">  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="1">1  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="2" checked>2  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="3">3  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="4">4  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="5">5  </label>  <p class="scale-ends"><span>Very easy</span><span>Very hard</span></p></div>
<div className="scale w-full max-w(280)" role="radiogroup" aria-label="How hard was it to set up?">  <label className="scale-option">    <input className="scale-input" type="radio" name="effort" value="1" />1  </label>  <label className="scale-option">    <input className="scale-input" type="radio" name="effort" value="2" defaultChecked />2  </label>  <label className="scale-option">    <input className="scale-input" type="radio" name="effort" value="3" />3  </label>  <label className="scale-option">    <input className="scale-input" type="radio" name="effort" value="4" />4  </label>  <label className="scale-option">    <input className="scale-input" type="radio" name="effort" value="5" />5  </label>  <p className="scale-ends"><span>Very easy</span><span>Very hard</span></p></div>
<div class="scale w-full max-w(280)" role="radiogroup" aria-label="How hard was it to set up?">  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="1">1  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="2" checked>2  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="3">3  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="4">4  </label>  <label class="scale-option">    <input class="scale-input" type="radio" name="effort" value="5">5  </label>  <p class="scale-ends"><span>Very easy</span><span>Very hard</span></p></div>
<template>  <div class="scale w-full max-w(280)" role="radiogroup" aria-label="How hard was it to set up?">    <label class="scale-option">      <input class="scale-input" type="radio" name="effort" value="1">1    </label>    <label class="scale-option">      <input class="scale-input" type="radio" name="effort" value="2" checked>2    </label>    <label class="scale-option">      <input class="scale-input" type="radio" name="effort" value="3">3    </label>    <label class="scale-option">      <input class="scale-input" type="radio" name="effort" value="4">4    </label>    <label class="scale-option">      <input class="scale-input" type="radio" name="effort" value="5">5    </label>    <p class="scale-ends"><span>Very easy</span><span>Very hard</span></p>  </div></template>

#尺度・セグメントコントロール・評価・スライダー

尺度は、中間の値にラベルを付けず、程度を表すために使います。名前の付いた 2〜5 個の選択肢で表示を切り替える場合はセグメントコントロールを使います。数個の星で点数を示す場合は評価、広い範囲からおおよその値を選ぶ場合はスライダー、投票を募り、全員の投票結果を表示する場合はアンケートを使います。

#アクセシビリティ

  • ラジオボタンは同じnameを共有します。ブラウザーはグループ全体を 1 つのタブストップとして扱い、矢印キーでグループ内を移動できるようにします。
  • セルの数値がラジオボタンのラベルになります。両端のラベルは個々のセルに関連付けられていないため、「0(まったく起こりそうにない)から 10(非常に起こりそう)まで」のように、数値の意味を質問文に含めます。
  • フォーカスリングはセルの外周に表示されます。タッチ画面ではセルの高さは変わらず、操作領域がセルの上下に広がって 44px になります。11 個のセルを押しやすく並べるには、約 320px の幅が必要です。
  • 尺度を無効にしても、選択済みのセルは控えめな色調で表示されるため、回答済みの値を確認できます。

#クラス

クラス説明
scalefieldset またはrole="radiogroup"を持つ要素に適用する行。セルは行の幅を分け合い、4px間隔で並びます。
scale-optionラベルに表示する1つの数値。高さ38px、最小幅28pxの平らな面で、すべてのセルが収まらなければ行が折り返す。押すとくぼみ、選択するとインク色のマークになる
scale-inputセル内のネイティブなラジオボタン。セル全体を覆い、ラジオボタン自体は描画されません。
scale-ends数値の列の下に置く行です。尺度の両端に対応するラベルを1つずつ配置します。

#カスタムプロパティ

プロパティ既定値説明
--scale-gap.25remセル同士の間隔

#ソース

@master/ui/components/scale.css
/* * Scale: one answer on a row of numbers, from one end to the other. * How likely, how satisfied, how much: each number is a <label> around a native radio, so the group keeps the * arrow keys and the form keeps the value. The cells share the row's width. At rest a cell is a flat face on * one contour; the chosen one is a mark of ink, as a chosen day of a calendar is. * scale-ends is a line under the row that names its two ends, since a number alone says nothing. * Geometry: cells are 38px tall, as a button is, 4px apart, with a small control's corner. On a touch screen a * cell's target reaches 44px above and below it. */@layer components.ui {  .scale {    --scale-gap: .25rem;    display: flex;    flex-wrap: wrap;    gap: var(--scale-gap);    min-width: 0;    margin: 0;    padding: 0;    border: 0;  }  /* One number. */  .scale-option {    position: relative;    display: grid;    flex: 1 1 0;    place-items: center;    /* A cell is never narrower than 28px: in a row too narrow for them all, the cells wrap. */    min-width: 1.75rem;    height: 2.375rem;    border-radius: calc(var(--radius-control-sm) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-raised);    color: var(--color-text-body);    box-shadow: var(--shadow-flat);    font: var(--font-weight-control) .84375rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    cursor: pointer;    touch-action: manipulation;    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    transition: box-shadow var(--duration-quick) var(--easing-glide);    @media (hover: hover) {      &:hover:not(:has(:checked, :disabled)) {        color: var(--color-text-strong);        box-shadow: 0 0 0 .5px var(--color-line-mark);      }    }    /* Pressed: the cell sinks into a well before it turns to ink. */    &:active:not(:has(:checked, :disabled)) {      background: var(--color-surface-inset);      box-shadow: var(--shadow-pressed);      transition-duration: var(--duration-press);    }    /* Chosen: ink. The face swaps at once; only its shadow eases. */    &:has(.scale-input:checked) {      background: var(--color-surface-inverse);      color: var(--color-text-inverse);      box-shadow: var(--shadow-ink-mark);    }    &:has(.scale-input:focus-visible) {      @apply --focus-ring;    }    &:has(.scale-input:disabled) {      background: var(--color-surface-inset);      color: var(--color-text-disabled);      cursor: not-allowed;    }    &:has(.scale-input:checked:disabled) {      background: var(--color-text-disabled);      color: var(--color-surface-raised);      box-shadow: none;    }    /* Cells stand 4px apart, so on touch a target grows only above and below. */    @media (pointer: coarse) {      &::after {        @apply --touch-target-block;      }    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      /* Kept out of forced colors, the chosen cell drops the theme's ink edge and shade along with its face. */      &:has(.scale-input:checked) {        background: Highlight;        color: HighlightText;        box-shadow: none;        forced-color-adjust: none;      }      /* A cell that cannot be chosen, chosen or not, is in the system's gray. */      &:has(.scale-input:disabled) {        outline-color: GrayText;        color: GrayText;      }      &:has(.scale-input:checked:disabled) {        background: GrayText;        color: Canvas;      }      /* The chosen cell is kept out of forced colors and is where the keys stand: its ring is given the system's color. */      &:has(.scale-input:focus-visible) {        outline: 2px solid Highlight;        outline-offset: 2px;      }    }  }  /* The native radio covers its cell and is not drawn: the cell is its face. */  .scale-input {    position: absolute;    inset: 0;    width: 100%;    height: 100%;    margin: 0;    padding: 0;    border: 0;    opacity: 0;    appearance: none;    cursor: inherit;  }  /* What the two ends mean: a line under the row, one name at each end. */  .scale-ends {    display: flex;    flex: none;    justify-content: space-between;    gap: 1rem;    order: 1;    width: 100%;    margin: .125rem 0 0;    color: var(--color-text-muted);    font-size: .78125rem;    line-height: 1.25rem;  }}