ナビゲーション

v2.1.0
構造

スクロール領域

コンテンツが続く側の端がフェードするスクロール領域。

このページの内容

スクロール領域は、パネル内の長いリスト、幅の広いテーブル、ログなどをページ内でスクロールできるようにする領域です。プラットフォーム標準のスクロール動作を保ち、細く控えめなスクロールバーを表示します。コンテンツが領域の外に続く側の端にはフェードがかかり、コンテンツの終端ではフェードが消えます。チャットやビルドログのように、読んでいる間に末尾が伸びていく領域では、追加される内容に追従させることもできます。

スクロール領域

<div class="sheet max-w(360) mx-auto">  <div class="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabindex="0" role="region" aria-label="Release notes">    <p class="m(0)">2.1 adds overlays that need no script.</p>    <p class="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>    <p class="m(0) mt-sm">      Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.    </p>    <p class="m(0) mt-sm">      The select draws its option list in the same material where the browser allows it.    </p>    <p class="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>    <p class="m(0) mt-sm">      Corners turn with continuous curvature where corner-shape is supported.    </p>    <p class="m(0) mt-sm">Every one of these falls back to a working component.</p>  </div></div>
<div className="sheet max-w(360) mx-auto">  <div className="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabIndex={0} role="region" aria-label="Release notes">    <p className="m(0)">2.1 adds overlays that need no script.</p>    <p className="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>    <p className="m(0) mt-sm">      Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.    </p>    <p className="m(0) mt-sm">      The select draws its option list in the same material where the browser allows it.    </p>    <p className="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>    <p className="m(0) mt-sm">      Corners turn with continuous curvature where corner-shape is supported.    </p>    <p className="m(0) mt-sm">Every one of these falls back to a working component.</p>  </div></div>
<div class="sheet max-w(360) mx-auto">  <div class="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabindex="0" role="region" aria-label="Release notes">    <p class="m(0)">2.1 adds overlays that need no script.</p>    <p class="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>    <p class="m(0) mt-sm">      Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.    </p>    <p class="m(0) mt-sm">      The select draws its option list in the same material where the browser allows it.    </p>    <p class="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>    <p class="m(0) mt-sm">      Corners turn with continuous curvature where corner-shape is supported.    </p>    <p class="m(0) mt-sm">Every one of these falls back to a working component.</p>  </div></div>
<template>  <div class="sheet max-w(360) mx-auto">    <div class="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabindex="0" role="region" aria-label="Release notes">      <p class="m(0)">2.1 adds overlays that need no script.</p>      <p class="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>      <p class="m(0) mt-sm">        Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.      </p>      <p class="m(0) mt-sm">        The select draws its option list in the same material where the browser allows it.      </p>      <p class="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>      <p class="m(0) mt-sm">        Corners turn with continuous curvature where corner-shape is supported.      </p>      <p class="m(0) mt-sm">Every one of these falls back to a working component.</p>    </div>  </div></template>
メモをスクロールすると、上に隠れた内容がある間は上端にフェードがかかり、末尾まで進むと下端のフェードが消えます。

#フェードの仕組み

フェードにはマスクを使い、その2つの色停止点をカスタムプロパティ--scroll-area-startと--scroll-area-endで指定します。領域自体のスクロールタイムライン上で2つのアニメーションがこれらの値を変化させます。最初の1.5remで始端のフェードが現れ、最後の1.5remで終端のフェードが消えます。スクリプトも監視用の要素も不要です。コンテンツがはみ出していないときはタイムラインが無効になり、どちらの端にもフェードはかかりません。

スクロール駆動アニメーションに対応していないブラウザーでも、領域は同じようにスクロールします。フェードは表示されません。

#スクロールの連鎖

ブロック軸では、スクロール領域の端に達したあともページを続けてスクロールできます。領域内をそれ以上スクロールできない状態で、その上からホイール操作やスワイプを始めると、ほかのコンテンツ上と同じようにページがスクロールします。スクロールの連鎖を抑えるのはインライン軸だけです。横にスワイプして行の端に達すると、そこで止まり、ブラウザーの「戻る」ジェスチャーは作動しません。

#インライン軸のスクロール

scroll-area-inlineは横方向にスクロールし、インライン軸の始端と終端にフェードをかけます。横一列に並んだカードや、カラム幅に収まらないテーブルに使えます。

インライン軸のスクロール

<div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Regions">  <div class="flex gap-sm w-fit py(4) px(2)">    <span class="chip">Tokyo</span>    <span class="chip">Singapore</span>    <span class="chip">Sydney</span>    <span class="chip">Mumbai</span>    <span class="chip">Frankfurt</span>    <span class="chip">London</span>    <span class="chip">Paris</span>    <span class="chip">Stockholm</span>    <span class="chip">Virginia</span>    <span class="chip">Oregon</span>    <span class="chip">São Paulo</span>    <span class="chip">Cape Town</span>  </div></div>
<div className="scroll-area scroll-area-inline" tabIndex={0} role="region" aria-label="Regions">  <div className="flex gap-sm w-fit py(4) px(2)">    <span className="chip">Tokyo</span>    <span className="chip">Singapore</span>    <span className="chip">Sydney</span>    <span className="chip">Mumbai</span>    <span className="chip">Frankfurt</span>    <span className="chip">London</span>    <span className="chip">Paris</span>    <span className="chip">Stockholm</span>    <span className="chip">Virginia</span>    <span className="chip">Oregon</span>    <span className="chip">São Paulo</span>    <span className="chip">Cape Town</span>  </div></div>
<div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Regions">  <div class="flex gap-sm w-fit py(4) px(2)">    <span class="chip">Tokyo</span>    <span class="chip">Singapore</span>    <span class="chip">Sydney</span>    <span class="chip">Mumbai</span>    <span class="chip">Frankfurt</span>    <span class="chip">London</span>    <span class="chip">Paris</span>    <span class="chip">Stockholm</span>    <span class="chip">Virginia</span>    <span class="chip">Oregon</span>    <span class="chip">São Paulo</span>    <span class="chip">Cape Town</span>  </div></div>
<template>  <div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Regions">    <div class="flex gap-sm w-fit py(4) px(2)">      <span class="chip">Tokyo</span>      <span class="chip">Singapore</span>      <span class="chip">Sydney</span>      <span class="chip">Mumbai</span>      <span class="chip">Frankfurt</span>      <span class="chip">London</span>      <span class="chip">Paris</span>      <span class="chip">Stockholm</span>      <span class="chip">Virginia</span>      <span class="chip">Oregon</span>      <span class="chip">São Paulo</span>      <span class="chip">Cape Town</span>    </div>  </div></template>

#追加される内容への追従

チャット、ビルドログ、ストリーミングされる回答は、読んでいる間に末尾が伸びていきます。領域にrole="log"を指定し、followビヘイビアを適用します。ビヘイビアは、内容が追加される間は末尾を表示し続け、読者が末尾からスクロールして離れた時点で追従をやめ、末尾に戻ると再び追従します。内容の後にhiddenを指定したscroll-area-latestボタンを置きます。このボタンは領域が追従していない間だけ表示され、押すと末尾までスクロールして再び追従します。

ビルドログへの追従

<div class="sheet max-w(440) mx-auto">  <div class="scroll-area h(240) p-md font-mono text-xs fg-text-body leading-md" tabindex="0" role="log" aria-label="Build log">    <div id="build-lines">      <p class="m(0)">Cloning master-co/ui at 3041b1c</p>      <p class="m(0)">Installing 596 packages</p>      <p class="m(0)">Compiling 112 stylesheets</p>    </div>    <button type="button" class="btn btn-sm btn-pill scroll-area-latest" hidden>      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" />      </svg>Jump to latest    </button>  </div></div><script>const steps = ['Checking contracts', 'Rendering /components', 'Rendering /blocks', 'Rendering /pages', 'Writing llms.txt', 'Writing the registry', 'Checking 2,914 links', 'Compressing assets', 'Uploading 71 pages']const lines = document.getElementById('build-lines')let count = 0const timer = setInterval(() => {  const line = document.createElement('p')  line.className = 'm(0)'  line.textContent = steps[count % steps.length] + (count >= steps.length ? ' (pass ' + (Math.floor(count / steps.length) + 1) + ')' : '')  lines.append(line)  if (++count >= 120) clearInterval(timer)}, 800)</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
行が次々に追加され、ログはそれに追従します。実行中に上にスクロールすると、ログはその位置に留まり、「Jump to latest」が表示されます。それを押すか、末尾までスクロールして戻ると、ログは再び追従します。

判断の仕組みは次のとおりです。

  • 追従。 ビヘイビアを適用した時点から追従します。領域を末尾までスクロールし、行の追加、最後のメッセージへのストリーミングされた単語の到着、画像の読み込み完了など、内容が増えるたびに再び末尾までスクロールします。
  • 停止。 ホイール、指、スクロールバー、↑、Page Up、Homeなど、どの方法でも先頭方向にスクロールすると追従をやめます。ホイールを先頭方向に回した場合は、領域が動く前に即座に停止するため、その瞬間に届いた単語が読者を引き戻すことはありません。
  • 再開。 End、スクロールバー、ボタンのいずれかで再び末尾に達すると、追従を再開します。末尾まで数ピクセル足りない位置も末尾とみなします。
  • イベント。 読者の操作で追従を開始または停止するたびに、領域はchangeを発行します。ビヘイビアのvalueは追従しているかどうかを示します。読者がメッセージを送信したときのアプリケーションのように、読者を末尾に移動させるにはtrueを設定します。設定してもイベントは発行されません。
app.js
import { follow } from '@master/ui/behaviors/follow.js'const log = document.querySelector('.scroll-area[role="log"]')const following = follow(log)form.addEventListener('submit', () => { following.value = true })

ビヘイビアがない場合、領域は通常のスクロール領域です。読者が最後にスクロールした位置を保ち、ボタンは非表示のままです。ボタンにはスティッキー配置が適用され、領域の下端に張り付いて、内容や端のフェードより手前に表示されます。最後の行の後ではなく上に重なるため、ボタンを表示しても内容の高さは変わりません。

#読んでいる位置の維持

上部に読み込まれる古いメッセージのように、読者が見ている位置より上に内容が挿入されると、読んでいる内容が下に押し下げられてしまいます。ブラウザーはスクロールアンカリングによってこれを自動的に防ぎます。上に追加された内容に合わせて領域内のスクロール位置を補正するため、読んでいるメッセージは表示上の位置を保ちます。スタイルシートは、領域にoverflow-anchor: auto、ボタンにnoneを指定します。ボタンがブラウザーの固定する要素になることはありません。スクロールアンカリングに対応していないブラウザーでは、followビヘイビアが、上の内容が動いた分だけスクロール位置を補正します。さらに読み込み中であることを示す注記など、行がその下に挿入される上部の行にもoverflow-anchor: noneを指定します。これにより、ブラウザーはその行ではなく、内容の行を固定します。

以前のメッセージとストリーミングされる回答

<div class="sheet max-w(440) mx-auto">  <div class="scroll-area h(320) p-md" tabindex="0" role="log" aria-label="Conversation with Ada">    <p class="m(0) pb-sm text-center text-xs fg-text-muted" style="overflow-anchor: none" id="earlier">      Earlier messages load as you scroll up    </p>    <ol class="m(0) p(0)" id="turns">      <li class="message message-sent">        <div class="message-bubble">Can the docs build run on every push?</div>      </li>      <li class="message">        <div class="message-bubble">Yes. It takes about two minutes.</div>      </li>    </ol>    <button type="button" class="btn btn-sm btn-pill scroll-area-latest" hidden>      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" />      </svg>Jump to latest    </button>  </div></div><script>const turns = document.getElementById('turns')const turn = (text, sent) => {  const item = document.createElement('li')  item.className = sent ? 'message message-sent' : 'message'  const bubble = document.createElement('div')  bubble.className = 'message-bubble'  bubble.textContent = text  item.append(bubble)  return item}const older = [['Morning! Is the release still today?', false], ['It is, once the docs build passes.', true], ['Which build?', false], ['The one that checks every page and link.', true], ['Do we wait for it?', false], ['No, it reports here when it is done.', true]]const log = turns.closest('.scroll-area')log.addEventListener('scroll', () => {  if (log.scrollTop > 48 || !older.length) return  for (const [text, sent] of older.splice(-2).reverse()) turns.prepend(turn(text, sent))  if (!older.length) document.getElementById('earlier').textContent = 'The start of the conversation'})const exchanges = [  ['What does it check?', 'It renders every page in five languages, checks each preview against the contracts, follows every link and compares the registry with the package, then writes the search index.'],  ['And if a link is broken?', 'The build stops and names the page and the link, so nothing half checked reaches the site. Fix it and push again; the next run starts from the beginning.'],  ['Thanks!', 'Any time. I will post here when this one is done.']]let at = 0const next = () => {  if (at >= exchanges.length) return  const [question, answer] = exchanges[at++]  turns.append(turn(question, true))  const reply = turn('', false)  const bubble = reply.firstChild  bubble.setAttribute('aria-busy', 'true')  turns.append(reply)  const words = answer.split(' ')  const stream = setInterval(() => {    bubble.textContent += (bubble.textContent ? ' ' : '') + words.shift()    if (words.length) return    clearInterval(stream)    bubble.removeAttribute('aria-busy')    setTimeout(next, 2500)  }, 140)}setTimeout(next, 1200)</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
回答がストリーミングで表示され、会話がそれに追従します。上にスクロールすると、先頭付近で古いやり取りが上に追加され、読んでいたやり取りはその位置に留まります。

#アクセシビリティ

  • スクロール領域はキーボードでフォーカスできる必要があります。すでにフォーカス可能なコンテンツが含まれている場合を除き、領域にtabindex="0"、regionなどのrole、ラベルを指定します。
  • マスクは、同じ端で領域自体のスクロールバーにもフェードをかけます。強制カラーモードではマスクが解除されます。
  • 領域には高さまたは最大の高さを指定します。指定しないと、領域はコンテンツに合わせて伸び、スクロールしません。
  • role="log"を指定したライブリージョンでは、aria-live の既定値は polite です。追加された内容はフォーカスを動かさずに読み上げられます。回答がメッセージにストリーミングされている間は、そのメッセージにaria-busy="true"を指定し、回答が完了したら削除します。これにより、メッセージは単語ごとではなく、完成した状態で一度だけ読み上げられます。
  • scroll-area-latestボタンは、表示されている間はタブ順序に含まれる実際のボタンです。押すとボタンは非表示になり、フォーカスは領域に移ります。その後はキー操作で領域をスクロールできます。
  • 追従によってフォーカスが動くことはなく、読者がスクロールして離れるとすぐに停止します。そのため、内容が次々に追加されても、読んでいる位置を保てます。

#キーボード操作

キー操作はブラウザー標準のもので、ビヘイビアはそれによるスクロールを監視するだけです。

キー操作
ArrowUp, ArrowDown, PageUp, PageDown, Home, Endブラウザー標準の動作と同様に、フォーカス中の領域をスクロール
ArrowUp, PageUp, Homefollow ビヘイビア使用時、先頭方向にスクロールすると追従を止め、scroll-area-latest ボタンを表示します。
Endfollow ビヘイビア使用時、末尾に戻ると領域は再び追従します。
Enter, Spacescroll-area-latest 上で、ボタンと同様に末尾までスクロールし、再び追従します。

#React、Svelte、Vue

logコンポーネントは、子要素の周りに追従するスクロール領域をボタン付きで描画し、ビヘイビアを適用して、followingを外部とやり取りします。npx master-ui add logでプロジェクトにコピーできます。コンポーネントの構成と使い方はReact、Svelte、Vueを参照してください。

ui/log.tsx
'use client'import { useState, type ComponentProps } from 'react'import { follow } from '@master/ui/behaviors/follow.js'import { useBehavior } from './use-behavior'export interface LogProps extends Omit<ComponentProps<'div'>, 'ref'> {  /** Whether the region keeps its end in view. It stops when the reader scrolls away and starts again at the end. */  following?: boolean  defaultFollowing?: boolean  onFollowingChange?: (following: boolean) => void  /** The words of the button that leads back to the end, such as "Jump to latest". */  latestLabel: string}/** * A scroll area that follows what arrives at its end: a chat, a build log, a streamed answer. Its children * are the content; name it with `aria-label` and give it a height. Set `following` to true to bring the * reader back to the end, as when they send a message. */export function Log({ following, defaultFollowing = true, onFollowingChange, latestLabel, className, children, ...root }: LogProps) {  const ref = useBehavior(follow, undefined, { value: following, defaultValue: defaultFollowing, onValueChange: onFollowingChange })  const [first] = useState(following ?? defaultFollowing)  return (    <div className={className ? `scroll-area ${className}` : 'scroll-area'} role="log" tabIndex={0} ref={ref} {...root}>      {children}      <button type="button" className="btn btn-sm btn-pill scroll-area-latest" hidden={first}>        <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fillRule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" /></svg>        {latestLabel}      </button>    </div>  )}
ui/Log.svelte
<script lang="ts" module>  import type { Snippet } from 'svelte'  import type { HTMLAttributes } from 'svelte/elements'  export interface LogProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {    /** What the region holds. */    children?: Snippet    /**     * Whether the region keeps its end in view. It stops when the reader scrolls away and starts again at the     * end. Bind it, or leave it out: it starts following.     */    following?: boolean    onFollowingChange?: (following: boolean) => void    /** The words of the button that leads back to the end, such as "Jump to latest". */    latestLabel: string  }</script><script lang="ts">  import { untrack } from 'svelte'  import { follow } from '@master/ui/behaviors/follow.js'  import { behavior } from './behavior.svelte.js'  let { children, following = $bindable(), onFollowingChange, latestLabel, class: className, ...root }: LogProps = $props()  const first = untrack(() => following) ?? true  const attach = behavior(follow, undefined, {    value: () => following,    change: (next) => { following = next; onFollowingChange?.(next) },  })</script><!--  @component  A scroll area that follows what arrives at its end: a chat, a build log, a streamed answer. Its children  are the content; name it with `aria-label` and give it a height. Set `following` to true to bring the  reader back to the end, as when they send a message.--><!-- A region that scrolls takes the focus, so the keys scroll it. --><!-- svelte-ignore a11y_no_noninteractive_tabindex --><div class={['scroll-area', className]} role="log" tabindex={0} {@attach attach} {...root}>  {@render children?.()}  <button type="button" class="btn btn-sm btn-pill scroll-area-latest" hidden={first}>    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" /></svg>    {latestLabel}  </button></div>
ui/Log.vue
<script setup lang="ts">import { useTemplateRef } from 'vue'import { follow } from '@master/ui/behaviors/follow.js'import { useBehavior } from './use-behavior'defineProps<{  /** The words of the button that leads back to the end, such as "Jump to latest". */  latestLabel: string}>()/** * Whether the region keeps its end in view: `v-model:following`. It stops when the reader scrolls away and * starts again at the end. */const following = defineModel<boolean>('following', { default: true })defineSlots<{  /** What the region holds. */  default?: () => unknown}>()/* * A scroll area that follows what arrives at its end: a chat, a build log, a streamed answer. Name it with * `aria-label` and give it a height. Set `following` to true to bring the reader back to the end, as when * they send a message. */// The button's hidden is the first state's attribute: after that it is the behavior's to move.const first = following.valueconst root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, follow, undefined, following)</script><template>  <div class="scroll-area" role="log" tabindex="0" ref="root">    <slot />    <button type="button" class="btn btn-sm btn-pill scroll-area-latest" :hidden="first">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" /></svg>      {{ latestLabel }}    </button>  </div></template>

#クラス

クラス説明
scroll-areaブロック軸に沿ってスクロールする領域。細いスクロールバーを備え、コンテンツが続く側の端はフェード表示
scroll-area-inlineインライン軸に沿ってスクロールし、始端と終端をフェードさせます。scroll-area と併用します
scroll-area-latest領域のコンテンツの後に置く btn に指定します。追従する領域の末尾に戻るためのボタンです。コンテンツに重ねて下端に固定し、フェードより前面に表示します。領域が追従している間は、ビヘイビアが hidden を付けます。

#カスタムプロパティ

プロパティ既定値説明
--scroll-area-fade1.5rem各辺のフェードの長さ

#ソース

@master/ui/components/scroll-area.css
/* * Scroll area: a region that scrolls inside the page, with a thin quiet scrollbar. * Where content continues past an edge, that edge fades out; where it ends, the edge is clean. The fade is * read from the scroll position itself by a scroll-driven animation, with no script and no sentinel elements. * Without scroll-driven animations the region scrolls the same and its edges stay clean. * A region that follows what arrives (role="log", with the follow behavior) keeps its end in view. Its * scroll-area-latest button is the way back to the end once the reader has scrolled away: a small raised pill * that stands over the content at the foot of the region, above the faded edge, and takes no room of its own. */@property --scroll-area-start {  syntax: '<length>';  inherits: false;  initial-value: 0px;}@property --scroll-area-end {  syntax: '<length>';  inherits: false;  initial-value: 0px;}@layer components.ui {  .scroll-area {    --scroll-area-fade: 1.5rem;    /* The latest button stands over the content inside the region, not over a sticky header outside it. */    isolation: isolate;    min-width: 0;    min-height: 0;    overflow: auto;    /*     * Only the inline axis keeps its scrolling to itself, so a sideways swipe never turns into the browser's back     * gesture. Along the block axis the page goes on scrolling past the region: a contained axis stops the wheel     * even where nothing overflows, which would leave a short region as a dead patch in the page.     */    overscroll-behavior-inline: contain;    scrollbar-width: thin;    scrollbar-color: var(--color-line-strong) transparent;    /* Content inserted above what the reader is looking at moves the region with it, so the reader's place holds. */    overflow-anchor: auto;    &:focus-visible {      @apply --focus-ring;    }    /* Scrolls along the inline axis: a row of cards, a wide table. */    &.scroll-area-inline {      overflow: auto hidden;    }    /*     * Two animations on the region's own scroll timeline. The first runs over the first stretch of scrolling     * and opens the fade at the start edge; the second runs over the last stretch and closes the fade at the     * end edge. While nothing overflows the timeline is inactive and both lengths stay 0.     */    @supports (animation-timeline: scroll()) {      /* The way the mask runs, from the start edge to the end edge of the scrolling axis. */      --scroll-area-run: to bottom;      mask-image: linear-gradient(var(--scroll-area-run), transparent, black var(--scroll-area-start), black calc(100% - var(--scroll-area-end)), transparent);      /* Longhands: tools that fold the timeline into the shorthand write a value no browser reads. */      animation-name: scroll-area-start, scroll-area-end;      animation-timing-function: linear;      animation-fill-mode: both;      animation-timeline: scroll(self block), scroll(self block);      animation-range: 0 var(--scroll-area-fade), calc(100% - var(--scroll-area-fade)) 100%;      /*       * What the keys or a link bring into view stops clear of the fade, so a focused control and its ring are       * never dimmed at the edge it was scrolled to.       */      scroll-padding-block: var(--scroll-area-fade);      /* Right to left, the start edge is on the right, so the mask runs the other way. */      &.scroll-area-inline {        --scroll-area-run: to right;        scroll-padding-block: 0;        scroll-padding-inline: var(--scroll-area-fade);        animation-timeline: scroll(self inline), scroll(self inline);        &:dir(rtl) {          --scroll-area-run: to left;        }      }      /* A mask cuts the region's own focus ring, which stands outside it: while the keys hold it, the fade steps aside. */      &:focus-visible {        mask-image: none;      }    }    /*     * While the way back to the end stands over the last rows, what the keys bring into view at the foot stops     * above it instead of under it: the room it stands in, a small button's 32px and a few pixels more.     */    &:has(.scroll-area-latest:not([hidden])) {      scroll-padding-block-end: calc(max(.75rem, var(--scroll-area-fade)) + 2.25rem);    }    @media (forced-colors: active) {      scrollbar-color: auto;      mask-image: none;    }    /*     * On a btn inside the region, after its content, and written inside the region so it outweighs the btn's     * own rules. Sticky at the foot, it stands above the fade, where nothing dims it; a negative margin of its     * own height lays it over the last row instead of after it, so showing it never makes the content taller.     * It is never the element scroll anchoring holds still.     */    .scroll-area-latest {      position: sticky;      inset-block-end: max(.75rem, var(--scroll-area-fade));      z-index: 1;      display: flex;      width: fit-content;      margin: calc(-1 * var(--btn-height, 2rem)) auto 0;      overflow-anchor: none;      transition-property: box-shadow, translate, color, opacity, display;      transition-behavior: allow-discrete;      &[hidden] {        display: none;        opacity: 0;        translate: 0 .375rem;      }      @starting-style {        opacity: 0;        translate: 0 .375rem;      }      @media (prefers-reduced-motion: reduce) {        &[hidden] {          translate: none;        }        @starting-style {          translate: none;        }      }    }  }}@keyframes scroll-area-start {  from {    --scroll-area-start: 0px;  }  to {    --scroll-area-start: var(--scroll-area-fade);  }}@keyframes scroll-area-end {  from {    --scroll-area-end: var(--scroll-area-fade);  }  to {    --scroll-area-end: 0px;  }}