通知の受信トレイは、読み手が離れている間に起きたことをまとめたページです。誰が行ったか、または何が起きたか、いつのことか、そして既読かどうかを示します。未読のものだけに絞り込み、1 件またはすべてを既読にできます。通知は、セグメントコントロールの下の、シートに載せたリストです。
通知の受信トレイ
<section class="sheet container-inline flex flex-col overflow-hidden max-w(640) mx-auto" data-example="notification-inbox" aria-labelledby="inbox-title"> <header class="flex flex-wrap items-center justify-between gap-sm p-md"> <div class="flex flex-col gap-3xs"> <h2 class="heading heading-sm" id="inbox-title">Notifications</h2> <p class="m(0) fg-text-muted" data-inbox-count>4 unread</p> </div> <div class="flex flex-wrap items-center gap-xs"> <div class="segmented segmented-sm" role="radiogroup" aria-label="Show"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="inbox-filter" value="all" checked disabled>All</label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="inbox-filter" value="unread" disabled>Unread</label> </div> <button type="button" class="btn btn-sm" data-inbox-read-all disabled>Mark all as read</button> </div> </header> <div class="px-md bt(1) bt-solid b-line-hair"> <ul class="list" aria-label="Notifications" data-inbox-list> <li class="list-row" data-unread> <span class="avatar list-media"> <img class="avatar-image" src="/demo/people/kenta-nakamura.webp" alt width="256" height="256"> </span> <div class="list-body"> <p class="list-title"> <a class="link link-quiet" href="#inbox-title">Kenta Nakamura mentioned you</a> </p> <p class="list-description">“Can you check the edge logs?”</p> </div> <p class="list-meta"> <time datetime="2026-11-13T09:31">Today, 09:31</time> <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span> </p> <span class="list-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Kenta Nakamura mentioned you” as read" data-inbox-read disabled> <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="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> </span> </li> <li class="list-row" data-unread> <span class="icon-frame icon-frame-xs list-media" aria-hidden="true"> <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="M8.8742 3.8235L13.4246 12.0144A1 1 0 0 1 12.5505 13.5L3.4495 13.5A1 1 0 0 1 2.5754 12.0144L7.1258 3.8235A1 1 0 0 1 8.8742 3.8235Z" /> <path d="M8 6.5L8 9" /> <circle cx="8" cy="11.5" r="0.5" fill="currentColor" stroke="none" /> </svg> </span> <div class="list-body"> <p class="list-title"> <a class="link link-quiet" href="#inbox-title">Deployment failed on atlas.dev</a> </p> <p class="list-description">The install step failed.</p> </div> <p class="list-meta"> <time datetime="2026-11-13T09:12">Today, 09:12</time> <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span> </p> <span class="list-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Deployment failed on atlas.dev” as read" data-inbox-read disabled> <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="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> </span> </li> <li class="list-row" data-unread> <span class="avatar list-media"> <img class="avatar-image" src="/demo/people/misaki-sato.webp" alt width="256" height="256"> </span> <div class="list-body"> <p class="list-title"> <a class="link link-quiet" href="#inbox-title">Misaki Sato left a comment</a> </p> <p class="list-description">“The hero reads much better.”</p> </div> <p class="list-meta"> <time datetime="2026-11-12T17:40">Yesterday, 17:40</time> <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span> </p> <span class="list-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Misaki Sato left a comment” as read" data-inbox-read disabled> <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="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> </span> </li> <li class="list-row" data-unread> <span class="icon-frame icon-frame-xs list-media" aria-hidden="true"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="8" cy="8" r="6" /> <path d="M8 4.3333L8 7.8892A0.2 0.2 0 0 0 8.094 8.0588L10.6667 9.6667" /> </svg> </span> <div class="list-body"> <p class="list-title"> <a class="link link-quiet" href="#inbox-title">Build minutes are at 62%</a> </p> <p class="list-description">760 minutes are left.</p> </div> <p class="list-meta"> <time datetime="2026-11-12T08:00">Yesterday, 08:00</time> <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span> </p> <span class="list-end"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Build minutes are at 62%” as read" data-inbox-read disabled> <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="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> </span> </li> <li class="list-row"> <span class="avatar list-media"> <img class="avatar-image" src="/demo/people/pohan-chen.webp" alt width="256" height="256"> </span> <div class="list-body"> <p class="list-title"> <a class="link link-quiet" href="#inbox-title">Po-han Chen invited you to Borealis</a> </p> <p class="list-description">You joined as a member.</p> </div> <p class="list-meta"> <time datetime="2026-11-11T14:05">11 November</time> </p> </li> <li class="list-row"> <span class="icon-frame icon-frame-xs list-media" aria-hidden="true"> <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="M4.4667 2L11.5333 2A0.8 0.8 0 0 1 12.3333 2.8L12.3333 12.7907A0.7018 0.7018 0 0 1 11.2833 13.4L10.4293 12.912A0.8 0.8 0 0 0 9.5886 12.9409L8.4438 13.7042A0.8 0.8 0 0 1 7.5562 13.7042L6.4114 12.9409A0.8 0.8 0 0 0 5.5707 12.912L4.7167 13.4A0.7018 0.7018 0 0 1 3.6667 12.7907L3.6667 2.8A0.8 0.8 0 0 1 4.4667 2Z" /> <path d="M6 5.3333L10 5.3333" /> <path d="M6 8.3333L10 8.3333" /> </svg> </span> <div class="list-body"> <p class="list-title"> <a class="link link-quiet" href="#inbox-title">Invoice INV-2026-011 was paid</a> </p> <p class="list-description">$100.00 for November.</p> </div> <p class="list-meta"> <time datetime="2026-11-01T00:00">1 November</time> </p> </li> </ul> <div data-inbox-empty hidden> <div class="empty"> <span class="icon-frame empty-media" aria-hidden="true"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3.5 10L7.8545 14.3545A0.2 0.2 0 0 0 8.1413 14.3504L16.5 5.5" /> </svg> </span> <h3 class="empty-title">You have read everything</h3> <p class="empty-description">Nothing is unread. What arrives next is listed here first.</p> <div class="empty-actions"> <button type="button" class="btn btn-sm" data-inbox-show-all>Show all notifications</button> </div> </div> </div> </div> <p class="sr-only" role="status" data-inbox-status></p></section>/** * An inbox of notifications on the page. The rows are markup the server wrote, so the list reads in full * without this script; the script reads which rows are unread into one list of its own and draws everything * from it: the rows that show, the count, whether "Mark all as read" can be pressed and the empty result. * Marking a row read is kept for this visit only: saving it, and anything arriving, is the application's. * Returns the function that stops it and puts every row back as it was. */export function mount(root) { const controller = new AbortController() const { signal } = controller const list = root.querySelector('[data-inbox-list]') const empty = root.querySelector('[data-inbox-empty]') const count = root.querySelector('[data-inbox-count]') const status = root.querySelector('[data-inbox-status]') const readAll = root.querySelector('[data-inbox-read-all]') const filters = [...root.querySelectorAll('[name="inbox-filter"]')] /** The one state: every notification, whether it is unread, and a copy of its row as it arrived. */ const items = [...list.children].map(row => ({ row, arrived: row.cloneNode(true), title: row.querySelector('.list-title').textContent.trim(), unread: row.hasAttribute('data-unread'), })) let filter = 'all' const unread = () => items.filter(item => item.unread).length const shown = () => items.filter(item => filter === 'all' || item.unread) const left = () => unread() ? `${unread()} unread.` : 'Nothing is unread.' const say = (message) => { status.textContent = message } const current = () => filters.find(input => input.checked) /** Draws the inbox from the state. A row that has been read loses its badge and its button for good. */ function render() { for (const { row, unread } of items) { if (unread) continue row.removeAttribute('data-unread') row.querySelector('[data-inbox-unread]')?.remove() row.querySelector('.list-end')?.remove() } const rows = shown().map(item => item.row) list.replaceChildren(...rows) empty.hidden = rows.length > 0 count.textContent = unread() ? `${unread()} unread` : 'All read' readAll.disabled = !unread() } function read(item) { // Focus goes to the next unread notification, then to the one before, then to the filter. const rows = [...list.children] const here = rows.indexOf(item.row) const others = rows.filter(row => row !== item.row && row.querySelector('[data-inbox-read]')) const next = others.find(row => rows.indexOf(row) > here) ?? others.findLast(row => rows.indexOf(row) < here) item.unread = false render() say(`“${item.title}” marked as read. ${left()}`) ;(next?.querySelector('[data-inbox-read]') ?? current()).focus() } list.addEventListener('click', (event) => { const button = event.target.closest('[data-inbox-read]') const item = button && items.find(item => item.row === button.closest('.list-row')) if (item) read(item) }, { signal }) readAll.addEventListener('click', () => { for (const item of items) item.unread = false // The button is disabled once nothing is unread, so focus leaves it first. current().focus() render() say('All notifications marked as read.') }, { signal }) /** Every way of changing the filter draws and says the same thing. */ function show(value) { filter = value render() const total = shown().length say(filter === 'unread' ? left() : `${total} ${total === 1 ? 'notification' : 'notifications'}. ${left()}`) } root.addEventListener('change', (event) => { if (event.target.name === 'inbox-filter') show(event.target.value) }, { signal }) root.querySelector('[data-inbox-show-all]').addEventListener('click', () => { filters[0].checked = true show('all') filters[0].focus() }, { signal }) const controls = [...filters, readAll, ...root.querySelectorAll('[data-inbox-read]')] for (const control of controls) control.disabled = false render() return () => { controller.abort() filters[0].checked = true list.replaceChildren(...items.map(item => item.arrived)) empty.hidden = true count.textContent = `${items.filter(item => item.arrived.hasAttribute('data-unread')).length} unread` readAll.disabled = true for (const input of filters) input.disabled = true say('') }}「Unread」(未読)に切り替え、チェックマークで通知を 1 件既読にしてから、残りを既読にしてみてください。既読の状態は、このプレビューの中でだけ保持されます。
ブロックはコピーして使えるマークアップです。文字色と文字サイズはページから引き継ぎます。プレビューでは body に fg-text-body text-sm を設定しています。各ブロックはサイズコンテナーで、広いページでも、サイドバーほどの幅でも、ダイアログ内でも、自身の幅に応じて配置が変わります。
#構成
- 読みやすい幅にした 1 枚のシート。
max-w(640)にします。タイトル、件数、操作を収めたヘッダーの後に、リストを置きます。ブロックが狭いときは、操作がタイトルの下に折り返します。 - 件数は、タイトルの下の言葉です。 「4 unread」(未読 4 件)のように示します。どちらも 1 つの状態から描画するため、行が示すのと同じ数になります。
- 「All」(すべて)と「Unread」の切り替えは、2 つのネイティブのラジオボタンによる
segmentedです。 フィルターはいくつかの中から 1 つを選ぶもので、それがまさにラジオグループです。矢印キーの操作とチェック状態はブラウザーが保ち、選択されていないものが「selected」と読み上げられることもありません。 - 各通知は
list-rowです。 誰が、または何がを示すlist-media、対象そのものへのリンクになっているタイトル、1 行の詳細、その下に届いた時刻で構成します。人はアバターで、システムはアイコンフレームで示すため、失敗したデプロイが人の顔を借りることはありません。 - 未読は言葉で示します。 ドット付きのニュートラルなバッジが、時刻の横に「Unread」と表示します。
aria-currentでもaria-selectedでもありません。どちらも「まだ読んでいない」という意味ではなく、行は新しいからといって選択されているわけでもないからです。 - 未読の行の末尾にある控えめなボタン 1 つで、その行を既読にします。ボタンの名前には行のタイトルが入ります。「Mark “Deployment failed on atlas.dev” as read」のようになります。既読になった行には、ボタンもバッジもありません。
- 「Mark all as read」(すべて既読にする)は、行ではなくフィルターと並べて置きます。 未読が 1 件もない間は無効です。
- 未読がないことと、何もないことは別です。 「Unread」のフィルターに行が 1 つも残らなくなったら、空の状態が「You have read everything」(すべて読み終えました)と伝え、すべての通知に戻る手段を示します。一度も通知が届いたことのない受信トレイは別の状態であり、別の文言が必要です。
タイトルと詳細はそれぞれ 1 行に収まり、はみ出す分は省略記号で終わります。通知は対象を指し示すものであり、残りは対象そのものが持っています。
#スクリプトが必要な処理
行はマークアップにあるため、受信トレイはスクリプトがなくてもすべて読めます。操作はマークアップでは disabled で、スクリプトが有効にします。その後 main.js は、1 つのリストを保ちます。すべての通知と、それぞれが未読かどうかで、行から一度だけ読み取ります。すべてはこのリストから描画されます。
- フィルターは、すべての行か、未読の行だけを表示します。件数、行、空の結果は、どれも個別には保持されないため、食い違うことがありません。
- 1 件を既読にすると、その行からバッジとボタンが取り除かれます。「Unread」を選んでいるときは、行もリストから外れます。
- フォーカスが後を追います。 行を既読にした後、フォーカスは次の未読の行のボタンへ移ります。それがなければ 1 つ前の行のボタンへ、未読が残っていなければフィルターへ移ります。「Mark all as read」は、無効になる前にフォーカスをフィルターへ渡します。
- 描画されない polite のステータス行 1 つが、結果と残りの件数を伝えます。「“Kenta Nakamura mentioned you” marked as read. 3 unread.」のようになります。
既読の状態は、その訪問の間だけ保持されます。アプリケーションでは、同じ関数が変更をサーバーに送信し、失敗した場合は行を未読に戻します。新しい通知はリストに追加し、同じ方法で数えます。このブロックはページの中にとどまります。ベルの下に開くポップオーバーではなく、プッシュ通知も送りません。
#アクセシビリティ
- ブロックは
<h2>を名前とする<section>で、リストは「Notifications」という名前の<ul>です。 - フィルターは「Show」という名前の
radiogroupです。Tab キーでチェックされている選択肢に移動し、矢印キーで選択を移します。 - 各行にはターゲットが 2 つあり、それぞれが何をするかを伝えます。タイトルは対象へ移動し、ボタンはその行を既読にします。ボタンの中のチェックマークは装飾で、名前は
aria-labelにあります。 - 名前の横にある顔写真の
altは空にし、アイコンフレームにはaria-hiddenを付けます。誰が、または何がは、すでにタイトルが伝えています。 - 時刻は
datetimeを付けた<time>です。「Today, 09:31」(今日 09:31)は読み手のためのもので、属性はそれ以外のすべてのためのものです。 - ステータス行は
role="status"なので、結果はフォーカスを移さずに読み上げられます。また、行がなくなっても、フォーカスがページの先頭に戻ることは決してありません。 - タッチスクリーンでは、32px のボタンは大きさを保ったまま、ターゲットが 44px に広がります。
#関連項目
- サーフェストレイ、シート、ウェル。すべてのコンポーネントの土台となる、奥行きの異なる素材です。
- セグメントコントロールくぼんだトラックに少数の選択肢を並べ、選択された項目へハイライトが滑らかに移動します。
- リスト画像やアイコン、テキスト、末尾の要素を並べた行の一覧。
- アバター人物やチームを写真やイニシャルで表し、単独でも重ねても使えます。
- アイコンフレーム見出しの横などで、アイコンを適切な大きさで収める小さなウェル。
- バッジステータス、カテゴリー、件数を示す小さなチップ。色に意味があるとき以外はニュートラルな色で表示します。
- 空の状態ビューに表示する内容がまだないときに示す状態です。
- ボタン面からわずかに浮いた操作要素です。ポインターを重ねるとさらに浮き上がり、押すと沈み込みます。
- リンク周囲の文と同じ文字色で表示する、移動先を持つテキストリンク。
- 見出しページの前景色で表示する見出しと、その上のラベル、下の導入文。