ナビゲーション

v2.1.0
フィードバック

キャレット

生成中や入力途中のテキストの末尾に表示するマーク。

このページの内容

キャレットは、生成中や入力途中のテキストの末尾に表示する細い縦線です。直前の文字と同じ色で、約1秒に1回の周期でフェードアウトとフェードインを繰り返します。ストリーミング中の回答や、入力を待つプロンプトの末尾で、テキストに続きがあることを伝えます。

キャレット

<div class="message w-full max-w(420)" aria-busy="true">  <div class="message-bubble">    The table has two million rows, so the column is added as nullable first and filled in batches of ten thousand<span class="caret" aria-hidden="true"></span>  </div></div>
<div className="message w-full max-w(420)" aria-busy="true">  <div className="message-bubble">    The table has two million rows, so the column is added as nullable first and filled in batches of ten thousand<span className="caret" aria-hidden="true"></span>  </div></div>
<div class="message w-full max-w(420)" aria-busy="true">  <div class="message-bubble">    The table has two million rows, so the column is added as nullable first and filled in batches of ten thousand<span class="caret" aria-hidden="true"></span>  </div></div>
<template>  <div class="message w-full max-w(420)" aria-busy="true">    <div class="message-bubble">      The table has two million rows, so the column is added as nullable first and filled in batches of ten thousand<span class="caret" aria-hidden="true"></span>    </div>  </div></template>

#配置

キャレットはテキストを含む要素の中で、末尾の文字の直後に何も挟まず配置します。行内の文字と同じ高さと色を使うインラインボックスなので、サイズやバリアントの指定は不要です。ページ、カード、インク色のサーフェスで、見出し、段落、コード行のいずれにも使えます。

テキストが完成したらキャレットを削除します。末尾で点滅し続けると、読み手はまだ続きがあると思って待ち続けます。

さまざまなテキストでの使用例

<h3 class="heading heading-lg">  Writing the migration<span class="caret" aria-hidden="true"></span></h3><p class="m(0) text-sm fg-text-body">  Checking the three services that read the column<span class="caret" aria-hidden="true"></span></p><pre class="code-block w-full"><code>$ bun run build<span class="caret caret-block" aria-hidden="true"></span></code></pre>
<>  <h3 className="heading heading-lg">    Writing the migration<span className="caret" aria-hidden="true"></span>  </h3>  <p className="m(0) text-sm fg-text-body">    Checking the three services that read the column<span className="caret" aria-hidden="true"></span>  </p>  <pre className="code-block w-full"><code>$ bun run build<span className="caret caret-block" aria-hidden="true"></span></code></pre></>
<h3 class="heading heading-lg">  Writing the migration<span class="caret" aria-hidden="true"></span></h3><p class="m(0) text-sm fg-text-body">  Checking the three services that read the column<span class="caret" aria-hidden="true"></span></p><pre class="code-block w-full"><code>$ bun run build<span class="caret caret-block" aria-hidden="true"></span></code></pre>
<template>  <h3 class="heading heading-lg">    Writing the migration<span class="caret" aria-hidden="true"></span>  </h3>  <p class="m(0) text-sm fg-text-body">    Checking the three services that read the column<span class="caret" aria-hidden="true"></span>  </p>  <pre class="code-block w-full"><code>$ bun run build<span class="caret caret-block" aria-hidden="true"></span></code></pre></template>

#ブロックキャレット

caret-blockは、ターミナルで使う幅0.5emのキャレットです。細い縦線が文字に見えやすい、シェルを表示するコードブロックやウィンドウで、コマンドの直後に使います。

#キャレット、シマー、入力中の表示

キャレットは、すでに表示され、さらに続きが追加されるテキストの末尾に使います。テキストがまだなく、短い文言で処理中と伝える場合はシマーを使います。チャットで相手が入力中なら、メッセージにmessage-typingを使います。コントロールの処理待ちにはスピナーを使います。

#アクセシビリティ

  • キャレットは装飾なので、aria-hidden="true"を指定します。
  • テキストを生成している領域にaria-busy="true"を指定し、完成したら外します。スクリーンリーダーは語句が追加されるたびに読み上げるのではなく、完成したテキストをまとめて一度読み上げられます。
  • prefers-reduced-motion: reduceでは点滅せず、テキストの末尾に静止したキャレットを表示します。

#クラス

クラス説明
caret直前の文字と同じ色で、文字と同じ高さの細い縦棒です。約 1 秒に 1 回、フェードアウトしてから元の表示に戻ります。
caret-blockターミナルのキャレット。幅は 0.5emcaret と併用します

#ソース

@master/ui/components/caret.css
/* * Caret: the mark at the end of text that is still being written. * A fine upright bar in the ink of the words it follows, as tall as their line of letters, that fades out * and back about once a second. It says "more is coming" where the words themselves cannot: at the end of an * answer as it streams, or after a prompt that waits. caret-block is the wide caret of a terminal. * With reduced motion it does not blink. It is decoration: hide it from assistive technology, and mark the * region that is being written with aria-busy. */@layer components.ui {  .caret {    display: inline-block;    width: max(2px, .1em);    height: 1.1em;    margin-inline-start: .125em;    border-radius: 999px;    corner-shape: round;    background: currentColor;    vertical-align: -.18em;    animation: caret-blink 1.1s var(--easing-glide) infinite;    /*     * A terminal's caret: half an em wide, with a square corner, a little lighter than the words. The blink     * animates opacity, so the lighter ink is mixed into the fill, not set as an opacity the blink would overrule.     */    &.caret-block {      width: .55em;      border-radius: 1px;      background: color-mix(in oklab, currentColor 80%, transparent);    }    @media (prefers-reduced-motion: reduce) {      animation: none;    }    @media (forced-colors: active) {      background: CanvasText;      &.caret-block {        background: CanvasText;      }    }  }}@keyframes caret-blink {  0%, 45% {    opacity: 1;  }  60%, 90% {    opacity: 0;  }}