ナビゲーション

v2.1.0
フォーム

チェックリスト

完了した項目数を表示する短いタスクリスト。

このページの内容

チェックリストは、セットアップの手順やレビューの確認事項など、やることをまとめた短いリストです。各手順では、タイトルと1行の補足を添えたラベルで、ネイティブのチェックボックスを囲みます。完了した手順は控えめに表示し、タイトルには細い取り消し線を引きます。完了数はリストが自動で集計します。

チェックリスト

<div class="card max-w(400) mx-auto">  <div class="card-header">    <h3 class="card-title">Get Atlas ready</h3>  </div>  <ul class="checklist">    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Create a project</span>          <span class="checklist-description">Atlas was created on 3 November.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Connect a repository</span>          <span class="checklist-description">Deploy every push to the main branch.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Add a domain</span>          <span class="checklist-description">Point a domain you own at the project.</span>        </span>        <span class="checklist-end"><span class="badge badge-sm">2 min</span></span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Invite your team</span>          <span class="checklist-description">Members can deploy and read the logs.</span>        </span>      </label>    </li>    <li class="checklist-count">steps done</li>  </ul></div>
<div className="card max-w(400) mx-auto">  <div className="card-header">    <h3 className="card-title">Get Atlas ready</h3>  </div>  <ul className="checklist">    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" defaultChecked />        <span className="checklist-body">          <span className="checklist-title">Create a project</span>          <span className="checklist-description">Atlas was created on 3 November.</span>        </span>      </label>    </li>    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" defaultChecked />        <span className="checklist-body">          <span className="checklist-title">Connect a repository</span>          <span className="checklist-description">Deploy every push to the main branch.</span>        </span>      </label>    </li>    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" />        <span className="checklist-body">          <span className="checklist-title">Add a domain</span>          <span className="checklist-description">Point a domain you own at the project.</span>        </span>        <span className="checklist-end"><span className="badge badge-sm">2 min</span></span>      </label>    </li>    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" />        <span className="checklist-body">          <span className="checklist-title">Invite your team</span>          <span className="checklist-description">Members can deploy and read the logs.</span>        </span>      </label>    </li>    <li className="checklist-count">steps done</li>  </ul></div>
<div class="card max-w(400) mx-auto">  <div class="card-header">    <h3 class="card-title">Get Atlas ready</h3>  </div>  <ul class="checklist">    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Create a project</span>          <span class="checklist-description">Atlas was created on 3 November.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Connect a repository</span>          <span class="checklist-description">Deploy every push to the main branch.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Add a domain</span>          <span class="checklist-description">Point a domain you own at the project.</span>        </span>        <span class="checklist-end"><span class="badge badge-sm">2 min</span></span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Invite your team</span>          <span class="checklist-description">Members can deploy and read the logs.</span>        </span>      </label>    </li>    <li class="checklist-count">steps done</li>  </ul></div>
<template>  <div class="card max-w(400) mx-auto">    <div class="card-header">      <h3 class="card-title">Get Atlas ready</h3>    </div>    <ul class="checklist">      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox" checked>          <span class="checklist-body">            <span class="checklist-title">Create a project</span>            <span class="checklist-description">Atlas was created on 3 November.</span>          </span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox" checked>          <span class="checklist-body">            <span class="checklist-title">Connect a repository</span>            <span class="checklist-description">Deploy every push to the main branch.</span>          </span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox">          <span class="checklist-body">            <span class="checklist-title">Add a domain</span>            <span class="checklist-description">Point a domain you own at the project.</span>          </span>          <span class="checklist-end"><span class="badge badge-sm">2 min</span></span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox">          <span class="checklist-body">            <span class="checklist-title">Invite your team</span>            <span class="checklist-description">Members can deploy and read the logs.</span>          </span>        </label>      </li>      <li class="checklist-count">steps done</li>    </ul>  </div></template>
手順にチェックを入れると、スクリプトなしでリスト下の件数が更新されます。

#件数の自動集計

2つのCSSカウンターで件数を集計します。checklist-itemごとに合計を1つ増やし、:has()で項目内のチェックボックスがオンかどうかを判定し、オンの項目ごとに完了数を1つ増やします。checklist-countで両方の件数を表示します。

カウンターはドキュメント順に処理されるため、両方の件数が確定する位置、つまりマークアップ内で全手順の後に件数表示を置きます。件数に続く文言は自分で記述できるので、翻訳も自由にできます。2つの数値の間に入る文字列は--checklist-ofで指定し、既定値は' / 'です。「2 of 4」のように表示するには' of 'を指定します。

件数は生成コンテンツです。表示は常に最新ですが、変更は読み上げられません。リストの完了を伝える必要がある場合は、別途ステータスメッセージを用意します。

#手順

行全体がラベルなので、テキストのどこを押してもチェックボックスをオンにできます。checklist-titleは意図的にインライン要素にしています。完了した項目のタイトルに引く取り消し線は、テキストに沿って伸びる背景で、タイトルが折り返されても1本のままです。checklist-endには、所要時間などを手順の末尾に表示できます。

リストと同様、行はテキストの先頭から伸びる細い線で区切ります。チェックリスト自体に背景面はないため、カードに入れて使います。

#アクセシビリティ

  • 通常は<ul>を使い、手順を順番どおりに進める必要がある場合は<ol>を使います。
  • ここでのチェックボックスは、読者が状態を切り替えるためのものです。システムが完了させる手順はステップで表示します。読者が変更できないチェックボックスは、完了の記録としては機能せず、無効なコントロールとして扱われます。
  • 取り消し線付きのタイトルには、読みやすいコントラストを保てる控えめな文字色を使います。完了状態はチェックボックスで伝えます。

#クラス

クラス説明
checklistul に適用するリスト。順に進めるステップには ol を使います。ステップの総数とチェック済みの数を数えます。
checklist-itemli に指定するステップ。自身をステップ数に含め、チェックボックスがオンの間は完了数にも含める
checklist-labelラベルはチェックボックス、テキストの順です。行全体でチェックを入れられ、タッチ画面では高さが 44px になります。
checklist-bodyステップの文言。タイトルの下に説明を配置
checklist-titleインライン要素に置くステップ名。完了時は細い取り消し線を表示
checklist-descriptionタイトル下の、控えめな色の補足説明
checklist-endステップ末尾のリンク、バッジ、時刻など
checklist-count完了したステップ数と全ステップ数を自身のテキストの前に表示します。マークアップでは最後のステップの後に置きます。

#カスタムプロパティ

プロパティ既定値説明
--checklist-of' / '完了数と総数の間に表示する区切り文字
--checklist-gap.75remチェックボックスとテキストの間隔

#ソース

@master/ui/components/checklist.css
/* * Checklist: a short list of things to do, each a native checkbox with a title and a line of help. * A row is a label, so the whole of it checks the box. A step that is done steps back: its title turns to * the muted ink and a hairline is drawn through it from its start, the way a pen would. * The list counts itself. CSS counters add up the rows and, with :has(), the checked ones; checklist-count * writes the two numbers after the rows, so "2 / 5" is always true without a script. * Rows part on hairlines that start at the text, as a list's do. A checklist has no surface of its own. */@layer components.ui {  .checklist {    --checklist-gap: .75rem;    --checklist-padding-y: .6875rem;    /* What stands between the two numbers of the count. */    --checklist-of: ' / ';    display: flex;    flex-direction: column;    min-width: 0;    margin: 0;    padding: 0;    color: var(--color-text-body);    font-size: .875rem;    line-height: 1.45;    list-style: none;    counter-reset: checklist-total checklist-done;    /* On touch a row is 44px: the same line of words with a little more room over and under it. */    @media (pointer: coarse) {      --checklist-padding-y: .75rem;    }  }  /* A step. It counts itself, and counts itself done while its checkbox is checked. */  .checklist-item {    position: relative;    min-width: 0;    margin: 0;    padding: 0;    counter-increment: checklist-total;    &:has(.checkbox:checked) {      counter-increment: checklist-total checklist-done;    }    /* The hairline under a step that another follows; it starts where the words do, past the 18px checkbox. */    &:has(+ .checklist-item)::after {      content: '';      position: absolute;      inset-inline: calc(1.125rem + var(--checklist-gap)) 0;      inset-block-end: 0;      height: 1px;      background: var(--color-line-hair);      pointer-events: none;      /* Forced colors would turn the hairline's fill to the canvas: it keeps a system color. */      @media (forced-colors: active) {        background: GrayText;      }    }  }  /* The label: the checkbox, then the words. The box is level with the first line of the title. */  .checklist-label {    display: flex;    align-items: flex-start;    gap: var(--checklist-gap);    min-width: 0;    padding: var(--checklist-padding-y) 0;    cursor: pointer;    touch-action: manipulation;    -webkit-tap-highlight-color: transparent;    &:has(.checkbox:disabled) {      cursor: not-allowed;    }    .checkbox {      flex: none;      margin-block-start: calc((1lh - var(--check-size)) / 2);    }  }  /* A block, not a grid: an item of a grid is made a block, and the title has to stay inline. */  .checklist-body {    display: block;    flex: 1 1 0;    /* The words and the end share the title's baseline; the box stands on the first line, as the box does. */    align-self: baseline;    min-width: 0;  }  /*   * The title is inline, so the stroke through it is one line however the title wraps: it is a background   * that grows from nothing to the title's whole length.   */  .checklist-title {    background: linear-gradient(currentColor, currentColor) 0 calc(50% + .0625em) / 0 1px no-repeat;    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    /* A long word or an address breaks inside the column, as the line of help under it does. */    overflow-wrap: anywhere;    transition-property: background-size, color;    transition-duration: var(--duration-base), var(--duration-quick);    transition-timing-function: var(--easing-glide);    /* Right to left the pen starts at the right. */    &:dir(rtl) {      background-position-x: 100%;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  .checklist-item:has(.checkbox:checked) .checklist-title {    background-size: 100% 1px;    color: var(--color-text-muted);  }  .checklist-item:has(.checkbox:disabled) .checklist-title {    color: var(--color-text-disabled);    /* Forced colors would give it the page's text color back: a step that cannot be ticked keeps the system's disabled ink. */    @media (forced-colors: active) {      color: GrayText;    }  }  .checklist-description {    display: block;    margin: .125rem 0 0;    color: var(--color-text-muted);    font-size: .8125rem;    text-wrap: pretty;    overflow-wrap: anywhere;  }  /*   * Something at the end of a step: a link to where it is done, a badge, a time. It belongs to the title, so it   * stands on the title's first line, as the box at the start does, not in the middle of the title and the line of   * help under it.   */  .checklist-end {    display: inline-flex;    flex: none;    align-items: center;    align-self: baseline;    gap: .5rem;    color: var(--color-text-muted);    font-size: .8125rem;    /* A time or a count, in figures of one width, as at the end of a list's row. */    font-variant-numeric: tabular-nums;  }  /*   * The count: how many steps are done, of how many. It comes after the steps in the markup, where the   * counters have their final values; its own words follow the numbers.   */  .checklist-count {    margin: .625rem 0 0;    color: var(--color-text-muted);    font-size: .8125rem;    font-variant-numeric: tabular-nums;    &::before {      content: counter(checklist-done) var(--checklist-of) counter(checklist-total) ' ';      color: var(--color-text-strong);      font-weight: var(--font-weight-control);    }  }}