上の帯
中身の上に貼り付く帯です。画面の見出しと、検索や操作を置きます。
見本で種類と状態を確かめる
高さ 56 で、スクロールしても上に残ります。767 以下は中央に画面名・左に戻る・右に操作 1〜2、768 以上は左に画面の見出し(title-2)・右に検索と操作です。768 以上の下の線は、スクロールしたときだけ出ます。
戻るあり
11月の明細
操作だけ
見通し
コードを写す
HTML
<header class="mz-topbar">
<div class="mz-topbar__lead"><button class="mz-icon-button" type="button" aria-label="明細の一覧に戻る"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg></button></div>
<h1 class="mz-topbar__title">11月の明細</h1>
<div class="mz-topbar__actions">
<div class="mz-search" role="search" aria-label="明細"><svg class="mz-search__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg><input class="mz-search__input" type="search" aria-label="明細を探す"><kbd class="mz-kbd mz-search__kbd" aria-hidden="true">/</kbd></div>
<button class="mz-button" data-size="sm" type="button">明細を取り込む</button>
</div>
</header>React の呼び出し方
<Topbar
title="11月の明細"
lead={<IconButton label="明細の一覧に戻る" icon={<ChevronLeft strokeWidth={1.5} aria-hidden="true" />} />}
actions={<Button size="sm">明細を取り込む</Button>}
/>実装を見る(react/Topbar.tsx)
React の実装(react/Topbar.tsx)
/**
* Topbar — 中身の上の帯(docs/spec/components.md「topbar」)。見た目は css/components/topbar.css だけが持つ。
* - .mz-app__main の先頭に置く。SP は中央に画面名(title-3)、768〜 は左に見出し(title-2)
* - lead:左の戻る(icon-button)。actions:右の search と操作(SP は 1〜2 つ)
* - 下の線は、768〜 ではスクロールしたときだけ出る(CSS の animation-timeline。JS は持たない)
*/
import { forwardRef, type HTMLAttributes, type ReactNode } from 'react';
export interface TopbarProps extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
title: ReactNode;
lead?: ReactNode;
actions?: ReactNode;
/** 見出しの段(画面の見出しなら 1) */
level?: 1 | 2;
}
export const Topbar = forwardRef<HTMLElement, TopbarProps>(function Topbar(
{ title, lead, actions, level = 1, className, ...rest },
ref,
) {
const Heading = level === 1 ? 'h1' : 'h2';
return (
<header ref={ref} className={className ? `mz-topbar ${className}` : 'mz-topbar'} {...rest}>
<div className="mz-topbar__lead">{lead}</div>
<Heading className="mz-topbar__title">{title}</Heading>
<div className="mz-topbar__actions">{actions}</div>
</header>
);
});スマホ(767 以下)では検索を icon-button にし、操作を 1〜2 つに絞ります。
HTML
<header class="mz-topbar">
<div class="mz-topbar__lead"><button class="mz-icon-button" type="button" aria-label="明細の一覧に戻る"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg></button></div>
<h1 class="mz-topbar__title">11月の明細</h1>
<div class="mz-topbar__actions">
<button class="mz-icon-button" type="button" aria-label="明細を探す"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg></button>
</div>
</header>いつ使うか
- アプリの各画面の先頭に置き、いまどの画面にいるかと、その画面でよく使う操作を出します。
- 操作は 1〜2 つにします。ほかは画面の中か、ポップオーバーで開くメニューに置きます。
- 帯の幅が足りないとき(文字 200% の 390 幅など)は、画面名を 2 行目に下ろします。
読み上げとキーボードにどう応えるか
- 画面名は、その画面の
h1にします(見本ではページの見出しと重ならないよう h3 にしています)。 - 戻るボタンには「明細の一覧に戻る」のように、戻る先の名前を付けます。
- 帯の下の線の動きはスクロールに合わせた不透明度だけで、動きを減らす設定でも意味は変わりません。
よい例と悪い例
更新日