ナビゲーション

v2.1.0
フィードバック

処理中

コンテンツを再取得中の領域に重ねるオーバーレイとスピナー。

このページの内容

処理中の状態は、フィルターを変更したカード、ページを読み込んでいるテーブル、保存中のフォームなど、既存のコンテンツを再取得する領域に使います。領域に busy を指定し、処理中は aria-busy="true" を設定します。領域の背景色に合わせたオーバーレイでコンテンツのコントラストを抑え、中央に回転するスピナーを表示します。既存のコンテンツの位置は保たれるため、新しいコンテンツが届いてもレイアウトが急にずれることはありません。

処理中

<article class="card busy w-full max-w(320)" id="revenue" aria-label="Revenue">  <header class="card-header">    <h3 class="card-title">Revenue</h3>    <p class="card-description">$48,200 this month, up 12% on October.</p>  </header>  <footer class="card-footer">    <button class="btn btn-sm" type="button" id="revenue-refresh">Refresh</button>  </footer></article><script>var card = document.getElementById('revenue')document.getElementById('revenue-refresh').addEventListener('click', function () {  card.setAttribute('aria-busy', 'true')  card.inert = true  setTimeout(function () {    card.removeAttribute('aria-busy')    card.inert = false  }, 1800)})</script>
「更新」を押すと、カードが 2 秒間、処理中になります。

#状態を表す属性

クラスを指定するだけでは何も描画されません。同じ要素の aria-busy="true" が状態を表します。スクリーンリーダーに伝わる状態とスタイルシートが参照する状態が同じ属性で決まるため、両者は常に一致します。処理が終わったら属性を削除するか、値を false にします。

オーバーレイは 160ms 後にフェードインします。すぐに終わる処理では一瞬だけ表示されることがなく、コンテンツがすでに表示されているのに、読者に待つよう案内することもありません。

処理中

<article class="card busy w-full max-w(320)" aria-busy="true" aria-label="Revenue" inert>  <header class="card-header">    <h3 class="card-title">Revenue</h3>    <p class="card-description">$48,200 this month, up 12% on October.</p>  </header>  <footer class="card-footer"><button class="btn btn-sm" type="button">Refresh</button></footer></article>
<article className="card busy w-full max-w(320)" aria-busy="true" aria-label="Revenue" inert>  <header className="card-header">    <h3 className="card-title">Revenue</h3>    <p className="card-description">$48,200 this month, up 12% on October.</p>  </header>  <footer className="card-footer">    <button className="btn btn-sm" type="button">Refresh</button>  </footer></article>
<article class="card busy w-full max-w(320)" aria-busy="true" aria-label="Revenue" inert>  <header class="card-header">    <h3 class="card-title">Revenue</h3>    <p class="card-description">$48,200 this month, up 12% on October.</p>  </header>  <footer class="card-footer"><button class="btn btn-sm" type="button">Refresh</button></footer></article>
<template>  <article class="card busy w-full max-w(320)" aria-busy="true" aria-label="Revenue" inert>    <header class="card-header">      <h3 class="card-title">Revenue</h3>      <p class="card-description">$48,200 this month, up 12% on October.</p>    </header>    <footer class="card-footer"><button class="btn btn-sm" type="button">Refresh</button></footer>  </article></template>

#オーバーレイ

オーバーレイの色は、シート、カード、ダイアログが公開する --surface-color をもとに合成します。カードにはグレーをかぶせず、カード自体の背景色を使ってコントラストを抑えます。独自の背景面を持たない領域では、ページのキャンバス色を使います。角の丸みは領域に揃え、スピナーの背後は不透明にして周囲を透かすため、リングに文字が重なって見えることはありません。

オーバーレイは下にある要素へのポインター操作を遮ります。キーボード操作も無効にするには、最初の例のように、処理中は inert 属性を追加し、処理が終わったら削除します。

--busy-size はスピナーの直径を指定します。既定は 20px です。

#処理中とスケルトンの使い分け

処理中の状態は、表示済みのコンテンツを差し替えるときに使います。初回の読み込みでは、スケルトン でコンテンツの形を示します。単一の操作要素だけで待ち時間が発生する場合は、その要素の中に スピナー を表示します。ボタンには専用の aria-busy 状態があります。

#アクセシビリティ

  • aria-busy="true" は、領域が更新中であることを支援技術に伝えます。支援技術は、属性が削除されるまで領域内の変更の読み上げを保留することがあります。
  • この属性だけでは、処理の開始は読み上げられません。処理中の領域の外にあるライブリージョンか、処理を開始した操作要素で、開始をテキストで伝えます。
  • 処理中は領域に inert を指定し、オーバーレイの下にある操作要素にフォーカスしたり、作動させたりできないようにします。
  • 動きを抑える設定が有効な場合は、スピナーの回転が遅くなります。強制カラーモードでは、オーバーレイにキャンバス色を使います。

#クラス

クラス説明
busy領域自体に指定します。aria-busy="true" の間は、領域の背景と同じ色の覆いで内容を目立たなくし、中央でスピナーが回転します。覆いは領域の角の形状に沿い、160ms 後に表示されます。

#カスタムプロパティ

プロパティ既定値説明
--busy-size1.25remスピナーの直径

#ソース

@master/ui/components/busy.css
/* * Busy: a region whose content is being fetched again. * While the region carries aria-busy="true", a veil in the color of the surface it lies on steps its content * back and a spinner turns in the middle, where the veil is whole. What was there stays where it was, so * nothing jumps when the new content arrives; for content that has never loaded, use a skeleton instead. * The veil waits 160ms before it shows: work that ends at once never flashes. It takes the region's own * corner and keeps the pointer off what is under it; add the inert attribute to keep the keyboard out too. */@layer components.ui {  .busy {    --busy-size: 1.25rem;    --busy-width: max(1.5px, calc(var(--busy-size) / 9));    --busy-surface: var(--surface-color, var(--color-surface-base));    position: relative;    &[aria-busy="true"] {      /*       * The veil and the spinner stack inside the region only: without its own stacking context their z-index       * would lift them over a sticky header of the page that scrolls over the region.       */      isolation: isolate;      /* The veil. */      &::before {        content: '';        position: absolute;        z-index: 2;        inset: 0;        border-radius: inherit;        corner-shape: inherit;        /* The veil is whole behind the spinner and thins out around it, so the ring never stands on a word. */        background:          radial-gradient(circle at center, var(--busy-surface) calc(var(--busy-size) * .7), transparent calc(var(--busy-size) * 1.7)),          color-mix(in oklab, var(--busy-surface) 62%, transparent);        cursor: progress;        animation: busy-arrive var(--duration-base) var(--easing-glide) 160ms both;      }      /* The spinner: the same fine ring as the spinner component, in the strong ink. */      &::after {        content: '';        position: absolute;        z-index: 3;        inset: 0;        width: var(--busy-size);        height: var(--busy-size);        margin: auto;        border-radius: 999px;        background: conic-gradient(from 90deg, color-mix(in oklab, var(--color-text-strong) 12%, transparent) 0 18%, var(--color-text-strong));        mask: radial-gradient(farthest-side, transparent calc(100% - var(--busy-width) - .5px), black calc(100% - var(--busy-width)), black calc(100% - .5px), transparent);        pointer-events: none;        animation: busy-arrive var(--duration-base) var(--easing-glide) 160ms both, busy-rotate .72s linear infinite;      }      @media (prefers-reduced-motion: reduce) {        &::after {          animation-duration: var(--duration-base), 1.8s;        }      }      /* The veil keeps its 160ms wait, as the spinner does: it fades in to its own opacity. */      @media (forced-colors: active) {        &::before {          background: Canvas;          opacity: .7;        }        &::after {          background: conic-gradient(from 90deg, GrayText 0 18%, CanvasText);          forced-color-adjust: none;        }      }    }  }}@keyframes busy-arrive {  from {    opacity: 0;  }}@keyframes busy-rotate {  to {    rotate: 360deg;  }}