ナビゲーション

v2.1.0
フォーム

カレンダー

1 か月分の日付から、1 日、複数の日、または期間を選べるカレンダー。2 か月を並べて表示することもできます。

このページの内容

カレンダーは、1 か月分の日付から選択するためのコンポーネントです。選べるのは 1 日、期間、複数の日付で、表示できるのは 1 か月、または2 か月の横並びです。ボタンを並べた ARIA グリッドで、各状態の見た目はスタイルシートが担い、日付の生成、月の切り替えボタン、矢印キーの操作は calendar の ビヘイビア が担います。カレンダー自体に背景面はありません。カード に配置したり、ポップオーバー に配置して日付ピッカーにしたりできます。

カレンダー

<div class="sheet p-md">  <div class="calendar">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />        </svg>      </button>      <h3 class="calendar-title" id="cal-title" aria-live="polite">        <button type="button" class="calendar-title-button" aria-description="Choose a month or a year"></button>      </h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />        </svg>      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="cal-title"></div>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="sheet p-md">      <div className="calendar">        <div className="calendar-header">          <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Previous month">            <ChevronLeftIcon className="icon" />          </button>          <h3 className="calendar-title" id="cal-title" aria-live="polite">            <button type="button" className="calendar-title-button" aria-description="Choose a month or a year"></button>          </h3>          <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Next month">            <ChevronRightIcon className="icon" />          </button>        </div>        <div className="calendar-grid" role="grid" aria-labelledby="cal-title"></div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left'  import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'</script><div class="sheet p-md" {@attach attach}>  <div class="calendar">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <ChevronLeftIcon class="icon" />      </button>      <h3 class="calendar-title" id="cal-title" aria-live="polite">        <button type="button" class="calendar-title-button" aria-description="Choose a month or a year"></button>      </h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <ChevronRightIcon class="icon" />      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="cal-title"></div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="sheet p-md">    <div class="calendar">      <div class="calendar-header">        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">          <ChevronLeftIcon class="icon" />        </button>        <h3 class="calendar-title" id="cal-title" aria-live="polite">          <button type="button" class="calendar-title-button" aria-description="Choose a month or a year"></button>        </h3>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">          <ChevronRightIcon class="icon" />        </button>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="cal-title"></div>    </div>  </div></template>
日付をクリックして選択します。月の切り替えには 2 つのボタンを使います。日付にフォーカスして矢印キーで移動することもできます。タイトルをクリックすると、別の月や年に移動できます。

マークアップはヘッダーと空のグリッドで構成します。ビヘイビアは月名を calendar-title に、曜日名と週ごとの日付を calendar-grid に書き込み、初期表示には今月を使います。スクリプトが動作するまではグリッドのマークアップがそのまま表示されます。実行前から日付を表示する必要がある場合は、下の 期間 の例のように、週ごとの日付を含めてサーバーでレンダリングします。ビヘイビアが適用されると、グリッドの内容が置き換わります。

#月と年

上のカレンダーのタイトルは、calendar-title 内のボタン calendar-title-button です。クリックするとグリッドがその年の 12 か月に切り替わり、もう一度クリックすると 10 年分の年に切り替わります。年の一覧では、その 10 年間の直前と直後の年も、控えめな文字色で表示されます。年を選ぶとその年の月が、月を選ぶとその月の日付が表示され、フォーカスは同じ日に置かれます。Escape を押すと、元の日付の表示に戻ります。

月と年は、同じグリッド内の calendar-period ボタンで、1 行に 3 つずつ並び、日付ボタンと同じ質感で描画されます。グリッドは 6 週ある月の高さを保つため、カレンダーの高さは変わりません。タイトルは常にグリッドが表示している範囲を示します(November 2026、2026、2020 – 2029)。月の切り替えボタンは、月の一覧では 1 年、年の一覧では 10 年単位で移動し、その名前は labels オプションで指定します。年の一覧ではそれ以上の階層がないため、タイトルボタンは無効になります。

ボタンを含まないタイトルは通常のタイトルのままで、カレンダーは日付の表示から切り替わりません。この移動機能は、1 か月表示のカレンダー向けです。

ヘッダーにネイティブの月と年のセレクトを置く方法もありましたが、採用していません。2 つのセレクトと 2 つの月切り替えボタンは、どの言語でも 36px の列 7 つ分の幅に収まるとは限りません。また、100 年分のリストはセレクトでは長いスクロールになり、スタイルを適用したセレクトのリストはまだすべてのブラウザーで使えるわけではありません。月と年のグリッドはカレンダー自体の質感で描画され、読み手がすでに使っているキー操作で扱えます。

#状態

各状態は、日付ボタンの属性またはクラスで表します。ビヘイビアがこれらを設定します。手書きやサーバー生成のマークアップでも同じ属性とクラスを指定します。

状態属性・クラス表示
今日aria-current="date"数字の下にドット
選択済みaria-selected="true"選択済みの チェックボックス と同じインク色の塗りつぶし
表示月の範囲外calendar-day-outside控えめな文字色
選択不可disabled無効状態の文字色

移動先の月や年にも同じ印が付きます。今日を含む月や年には aria-current="date"、選択した日付を含むものには aria-selected="true"、min と max の間に日付がないものには disabled が付きます。calendar-period-outside は、表示対象の 10 年間の直前と直後の年を示します。

日付ボタンは、メニュー の項目と同じように、ポインターを重ねるとすぐに反応します。今日の日付を選択したときもドットは残り、その日付の文字色に揃います。

#期間

期間の始点と終点をインク色で塗りつぶし、チップと同系色の帯でつなぎます。開始日には calendar-day-range-start、終了日には calendar-day-range-end、その間の日付には calendar-day-range を指定します。期間内のすべての日付に aria-selected="true" を指定します。

このプレビューはマークアップだけで構成し、スクリプトは適用していません。「コード」ビューでは、ビヘイビアが生成する形式の 1 か月分のマークアップと、期間、今日、選択できない 2 つの日付の指定を確認できます。

期間

<div class="sheet p-md">  <div class="calendar">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />        </svg>      </button>      <h3 class="calendar-title" id="range-title" aria-live="polite">November 2026</h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />        </svg>      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="range-title">      <div class="calendar-week" role="row">        <span class="calendar-weekday" role="columnheader" aria-label="Sunday">Sun</span>        <span class="calendar-weekday" role="columnheader" aria-label="Monday">Mon</span>        <span class="calendar-weekday" role="columnheader" aria-label="Tuesday">Tue</span>        <span class="calendar-weekday" role="columnheader" aria-label="Wednesday">Wed</span>        <span class="calendar-weekday" role="columnheader" aria-label="Thursday">Thu</span>        <span class="calendar-weekday" role="columnheader" aria-label="Friday">Fri</span>        <span class="calendar-weekday" role="columnheader" aria-label="Saturday">Sat</span>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 1, 2026">          1        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 2, 2026">          2        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 3, 2026">          3        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 4, 2026">          4        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 5, 2026">          5        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 6, 2026" disabled>          6        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 7, 2026" disabled>          7        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 8, 2026">          8        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 9, 2026">          9        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 10, 2026">          10        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 11, 2026" aria-current="date">          11        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 12, 2026">          12        </button>        <button type="button" class="calendar-day calendar-day-range-start" role="gridcell" tabindex="0" aria-label="Friday, November 13, 2026" aria-selected="true">          13        </button>        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Saturday, November 14, 2026" aria-selected="true">          14        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Sunday, November 15, 2026" aria-selected="true">          15        </button>        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Monday, November 16, 2026" aria-selected="true">          16        </button>        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Tuesday, November 17, 2026" aria-selected="true">          17        </button>        <button type="button" class="calendar-day calendar-day-range-end" role="gridcell" tabindex="-1" aria-label="Wednesday, November 18, 2026" aria-selected="true">          18        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 19, 2026">          19        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 20, 2026">          20        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 21, 2026">          21        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 22, 2026">          22        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 23, 2026">          23        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 24, 2026">          24        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 25, 2026">          25        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 26, 2026">          26        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 27, 2026">          27        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 28, 2026">          28        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 29, 2026">          29        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 30, 2026">          30        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Tuesday, December 1, 2026">          1        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Wednesday, December 2, 2026">          2        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Thursday, December 3, 2026">          3        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Friday, December 4, 2026">          4        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Saturday, December 5, 2026">          5        </button>      </div>    </div>  </div></div>
import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'<div className="sheet p-md">  <div className="calendar">    <div className="calendar-header">      <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <ChevronLeftIcon className="icon" />      </button>      <h3 className="calendar-title" id="range-title" aria-live="polite">November 2026</h3>      <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <ChevronRightIcon className="icon" />      </button>    </div>    <div className="calendar-grid" role="grid" aria-labelledby="range-title">      <div className="calendar-week" role="row">        <span className="calendar-weekday" role="columnheader" aria-label="Sunday">Sun</span>        <span className="calendar-weekday" role="columnheader" aria-label="Monday">Mon</span>        <span className="calendar-weekday" role="columnheader" aria-label="Tuesday">Tue</span>        <span className="calendar-weekday" role="columnheader" aria-label="Wednesday">Wed</span>        <span className="calendar-weekday" role="columnheader" aria-label="Thursday">Thu</span>        <span className="calendar-weekday" role="columnheader" aria-label="Friday">Fri</span>        <span className="calendar-weekday" role="columnheader" aria-label="Saturday">Sat</span>      </div>      <div className="calendar-week" role="row">        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Sunday, November 1, 2026">          1        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Monday, November 2, 2026">          2        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Tuesday, November 3, 2026">          3        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Wednesday, November 4, 2026">          4        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Thursday, November 5, 2026">          5        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Friday, November 6, 2026" disabled>          6        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Saturday, November 7, 2026" disabled>          7        </button>      </div>      <div className="calendar-week" role="row">        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Sunday, November 8, 2026">          8        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Monday, November 9, 2026">          9        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Tuesday, November 10, 2026">          10        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Wednesday, November 11, 2026" aria-current="date">          11        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Thursday, November 12, 2026">          12        </button>        <button type="button" className="calendar-day calendar-day-range-start" role="gridcell" tabIndex={0} aria-label="Friday, November 13, 2026" aria-selected="true">          13        </button>        <button type="button" className="calendar-day calendar-day-range" role="gridcell" tabIndex={-1} aria-label="Saturday, November 14, 2026" aria-selected="true">          14        </button>      </div>      <div className="calendar-week" role="row">        <button type="button" className="calendar-day calendar-day-range" role="gridcell" tabIndex={-1} aria-label="Sunday, November 15, 2026" aria-selected="true">          15        </button>        <button type="button" className="calendar-day calendar-day-range" role="gridcell" tabIndex={-1} aria-label="Monday, November 16, 2026" aria-selected="true">          16        </button>        <button type="button" className="calendar-day calendar-day-range" role="gridcell" tabIndex={-1} aria-label="Tuesday, November 17, 2026" aria-selected="true">          17        </button>        <button type="button" className="calendar-day calendar-day-range-end" role="gridcell" tabIndex={-1} aria-label="Wednesday, November 18, 2026" aria-selected="true">          18        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Thursday, November 19, 2026">          19        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Friday, November 20, 2026">          20        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Saturday, November 21, 2026">          21        </button>      </div>      <div className="calendar-week" role="row">        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Sunday, November 22, 2026">          22        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Monday, November 23, 2026">          23        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Tuesday, November 24, 2026">          24        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Wednesday, November 25, 2026">          25        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Thursday, November 26, 2026">          26        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Friday, November 27, 2026">          27        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Saturday, November 28, 2026">          28        </button>      </div>      <div className="calendar-week" role="row">        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Sunday, November 29, 2026">          29        </button>        <button type="button" className="calendar-day" role="gridcell" tabIndex={-1} aria-label="Monday, November 30, 2026">          30        </button>        <button type="button" className="calendar-day calendar-day-outside" role="gridcell" tabIndex={-1} aria-label="Tuesday, December 1, 2026">          1        </button>        <button type="button" className="calendar-day calendar-day-outside" role="gridcell" tabIndex={-1} aria-label="Wednesday, December 2, 2026">          2        </button>        <button type="button" className="calendar-day calendar-day-outside" role="gridcell" tabIndex={-1} aria-label="Thursday, December 3, 2026">          3        </button>        <button type="button" className="calendar-day calendar-day-outside" role="gridcell" tabIndex={-1} aria-label="Friday, December 4, 2026">          4        </button>        <button type="button" className="calendar-day calendar-day-outside" role="gridcell" tabIndex={-1} aria-label="Saturday, December 5, 2026">          5        </button>      </div>    </div>  </div></div>
<script>  import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left'  import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'</script><div class="sheet p-md">  <div class="calendar">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <ChevronLeftIcon class="icon" />      </button>      <h3 class="calendar-title" id="range-title" aria-live="polite">November 2026</h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <ChevronRightIcon class="icon" />      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="range-title">      <div class="calendar-week" role="row">        <span class="calendar-weekday" role="columnheader" aria-label="Sunday">Sun</span>        <span class="calendar-weekday" role="columnheader" aria-label="Monday">Mon</span>        <span class="calendar-weekday" role="columnheader" aria-label="Tuesday">Tue</span>        <span class="calendar-weekday" role="columnheader" aria-label="Wednesday">Wed</span>        <span class="calendar-weekday" role="columnheader" aria-label="Thursday">Thu</span>        <span class="calendar-weekday" role="columnheader" aria-label="Friday">Fri</span>        <span class="calendar-weekday" role="columnheader" aria-label="Saturday">Sat</span>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 1, 2026">          1        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 2, 2026">          2        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 3, 2026">          3        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 4, 2026">          4        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 5, 2026">          5        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 6, 2026" disabled>          6        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 7, 2026" disabled>          7        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 8, 2026">          8        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 9, 2026">          9        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 10, 2026">          10        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 11, 2026" aria-current="date">          11        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 12, 2026">          12        </button>        <button type="button" class="calendar-day calendar-day-range-start" role="gridcell" tabindex="0" aria-label="Friday, November 13, 2026" aria-selected="true">          13        </button>        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Saturday, November 14, 2026" aria-selected="true">          14        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Sunday, November 15, 2026" aria-selected="true">          15        </button>        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Monday, November 16, 2026" aria-selected="true">          16        </button>        <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Tuesday, November 17, 2026" aria-selected="true">          17        </button>        <button type="button" class="calendar-day calendar-day-range-end" role="gridcell" tabindex="-1" aria-label="Wednesday, November 18, 2026" aria-selected="true">          18        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 19, 2026">          19        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 20, 2026">          20        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 21, 2026">          21        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 22, 2026">          22        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 23, 2026">          23        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 24, 2026">          24        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 25, 2026">          25        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 26, 2026">          26        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 27, 2026">          27        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 28, 2026">          28        </button>      </div>      <div class="calendar-week" role="row">        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 29, 2026">          29        </button>        <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 30, 2026">          30        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Tuesday, December 1, 2026">          1        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Wednesday, December 2, 2026">          2        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Thursday, December 3, 2026">          3        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Friday, December 4, 2026">          4        </button>        <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Saturday, December 5, 2026">          5        </button>      </div>    </div>  </div></div>
<script setup>import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'</script><template>  <div class="sheet p-md">    <div class="calendar">      <div class="calendar-header">        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">          <ChevronLeftIcon class="icon" />        </button>        <h3 class="calendar-title" id="range-title" aria-live="polite">November 2026</h3>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">          <ChevronRightIcon class="icon" />        </button>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="range-title">        <div class="calendar-week" role="row">          <span class="calendar-weekday" role="columnheader" aria-label="Sunday">Sun</span>          <span class="calendar-weekday" role="columnheader" aria-label="Monday">Mon</span>          <span class="calendar-weekday" role="columnheader" aria-label="Tuesday">Tue</span>          <span class="calendar-weekday" role="columnheader" aria-label="Wednesday">Wed</span>          <span class="calendar-weekday" role="columnheader" aria-label="Thursday">Thu</span>          <span class="calendar-weekday" role="columnheader" aria-label="Friday">Fri</span>          <span class="calendar-weekday" role="columnheader" aria-label="Saturday">Sat</span>        </div>        <div class="calendar-week" role="row">          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 1, 2026">            1          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 2, 2026">            2          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 3, 2026">            3          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 4, 2026">            4          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 5, 2026">            5          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 6, 2026" disabled>            6          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 7, 2026" disabled>            7          </button>        </div>        <div class="calendar-week" role="row">          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 8, 2026">            8          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 9, 2026">            9          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 10, 2026">            10          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 11, 2026" aria-current="date">            11          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 12, 2026">            12          </button>          <button type="button" class="calendar-day calendar-day-range-start" role="gridcell" tabindex="0" aria-label="Friday, November 13, 2026" aria-selected="true">            13          </button>          <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Saturday, November 14, 2026" aria-selected="true">            14          </button>        </div>        <div class="calendar-week" role="row">          <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Sunday, November 15, 2026" aria-selected="true">            15          </button>          <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Monday, November 16, 2026" aria-selected="true">            16          </button>          <button type="button" class="calendar-day calendar-day-range" role="gridcell" tabindex="-1" aria-label="Tuesday, November 17, 2026" aria-selected="true">            17          </button>          <button type="button" class="calendar-day calendar-day-range-end" role="gridcell" tabindex="-1" aria-label="Wednesday, November 18, 2026" aria-selected="true">            18          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 19, 2026">            19          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 20, 2026">            20          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 21, 2026">            21          </button>        </div>        <div class="calendar-week" role="row">          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 22, 2026">            22          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 23, 2026">            23          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Tuesday, November 24, 2026">            24          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Wednesday, November 25, 2026">            25          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Thursday, November 26, 2026">            26          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Friday, November 27, 2026">            27          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Saturday, November 28, 2026">            28          </button>        </div>        <div class="calendar-week" role="row">          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Sunday, November 29, 2026">            29          </button>          <button type="button" class="calendar-day" role="gridcell" tabindex="-1" aria-label="Monday, November 30, 2026">            30          </button>          <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Tuesday, December 1, 2026">            1          </button>          <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Wednesday, December 2, 2026">            2          </button>          <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Thursday, December 3, 2026">            3          </button>          <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Friday, December 4, 2026">            4          </button>          <button type="button" class="calendar-day calendar-day-outside" role="gridcell" tabindex="-1" aria-label="Saturday, December 5, 2026">            5          </button>        </div>      </div>    </div>  </div></template>

帯がひと続きの形に見えるよう、次のように描画します。

  • 列の間に隙間を設けず、帯をセルからセルへつなげます。行の間には 2px の隙間を設け、週ごとに帯を分けます。
  • 期間が週をまたぐ場合、週の境目で帯の端を丸めます。
  • 開始日と終了日では、セルのうち期間の内側に面する半分を帯で覆い、その上にインク色で塗りつぶした日付ボタンを重ねます。これにより、帯は日付ボタンの丸い縁より内側に入り、中央まで届きます。

range オプションを指定すると、ビヘイビアで期間を選択できます。1 回目のクリックで開始日、2 回目で終了日を選び、3 回目は新しい期間の選択を開始します。2 回目に選んだ日付のほうが早い場合は、日付順に並べ替えます。

期間を選択する

<div class="sheet p-md">  <div class="calendar" id="stay">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />        </svg>      </button>      <h3 class="calendar-title" id="stay-title" aria-live="polite"></h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />        </svg>      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="stay-title"></div>  </div></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.calendar(document.getElementById('stay'), { range: true, value: ['2026-11-13', '2026-11-18'] })})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach, calendar } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => {    const detach = [      attach(root.current!),      calendar(document.getElementById('stay')!, { range: true, value: ['2026-11-13', '2026-11-18'] }),    ]    return () => detach.forEach(stop => stop())  }, [])  return (    <div ref={root} className="sheet p-md">      <div className="calendar" id="stay">        <div className="calendar-header">          <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Previous month">            <ChevronLeftIcon className="icon" />          </button>          <h3 className="calendar-title" id="stay-title" aria-live="polite"></h3>          <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Next month">            <ChevronRightIcon className="icon" />          </button>        </div>        <div className="calendar-grid" role="grid" aria-labelledby="stay-title"></div>      </div>    </div>  )}
<script>  import { attach, calendar } from '@master/ui/behaviors'  import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left'  import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'  function mounted(root) {    const detach = [      attach(root),      calendar(document.getElementById('stay'), { range: true, value: ['2026-11-13', '2026-11-18'] }),    ]    return () => detach.forEach(stop => stop())  }</script><div class="sheet p-md" {@attach mounted}>  <div class="calendar" id="stay">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <ChevronLeftIcon class="icon" />      </button>      <h3 class="calendar-title" id="stay-title" aria-live="polite"></h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <ChevronRightIcon class="icon" />      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="stay-title"></div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, calendar } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'const root = ref(null)let detach = []onMounted(() => {  detach = [    attach(root.value),    calendar(document.getElementById('stay'), { range: true, value: ['2026-11-13', '2026-11-18'] }),  ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template>  <div ref="root" class="sheet p-md">    <div class="calendar" id="stay">      <div class="calendar-header">        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">          <ChevronLeftIcon class="icon" />        </button>        <h3 class="calendar-title" id="stay-title" aria-live="polite"></h3>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">          <ChevronRightIcon class="icon" />        </button>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="stay-title"></div>    </div>  </div></template>
開始日をクリックし、次に終了日をクリックします。

attach() はオプションを渡さないため、このプレビューでは attach() の実行後に calendar を明示的に呼び出します。同じルートに対して 2 回呼び出すと、2 回目に適用したビヘイビアが 1 回目のものを置き換えます。MasterUI はプレビューが読み込むバンドルです。プロジェクトでは、ビヘイビア セクションの例に従って calendar をインポートします。

#複数の日付

multiple オプションを指定すると、ビヘイビアで任意の数の離れた日付を選択できます。クリック、Enter、Space で日付の選択を切り替えます。選択されたすべての日付に aria-selected="true" が付き、グリッドには aria-multiselectable="true" が付きます。値は選択した日付を YYYY-MM-DD 形式で並べ替えたリストで、変更のたびにそのすべてがイベントで渡されます。

複数の日付

<div class="sheet p-md">  <div class="calendar" id="shifts">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />        </svg>      </button>      <h3 class="calendar-title" id="shifts-title" aria-live="polite"></h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />        </svg>      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="shifts-title"></div>  </div></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.calendar(document.getElementById('shifts'), {  multiple: true,  value: ['2026-11-09', '2026-11-12', '2026-11-20'],  disabled: function (date) { return date.getDay() === 0 || date.getDay() === 6 }})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach, calendar } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => {    const detach = [      attach(root.current!),      calendar(document.getElementById('shifts')!, {        multiple: true,        value: ['2026-11-09', '2026-11-12', '2026-11-20'],        disabled: function (date) { return date.getDay() === 0 || date.getDay() === 6 }      }),    ]    return () => detach.forEach(stop => stop())  }, [])  return (    <div ref={root} className="sheet p-md">      <div className="calendar" id="shifts">        <div className="calendar-header">          <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Previous month">            <ChevronLeftIcon className="icon" />          </button>          <h3 className="calendar-title" id="shifts-title" aria-live="polite"></h3>          <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Next month">            <ChevronRightIcon className="icon" />          </button>        </div>        <div className="calendar-grid" role="grid" aria-labelledby="shifts-title"></div>      </div>    </div>  )}
<script>  import { attach, calendar } from '@master/ui/behaviors'  import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left'  import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'  function mounted(root) {    const detach = [      attach(root),      calendar(document.getElementById('shifts'), {        multiple: true,        value: ['2026-11-09', '2026-11-12', '2026-11-20'],        disabled: function (date) { return date.getDay() === 0 || date.getDay() === 6 }      }),    ]    return () => detach.forEach(stop => stop())  }</script><div class="sheet p-md" {@attach mounted}>  <div class="calendar" id="shifts">    <div class="calendar-header">      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">        <ChevronLeftIcon class="icon" />      </button>      <h3 class="calendar-title" id="shifts-title" aria-live="polite"></h3>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">        <ChevronRightIcon class="icon" />      </button>    </div>    <div class="calendar-grid" role="grid" aria-labelledby="shifts-title"></div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, calendar } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'const root = ref(null)let detach = []onMounted(() => {  detach = [    attach(root.value),    calendar(document.getElementById('shifts'), {      multiple: true,      value: ['2026-11-09', '2026-11-12', '2026-11-20'],      disabled: function (date) { return date.getDay() === 0 || date.getDay() === 6 }    }),  ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template>  <div ref="root" class="sheet p-md">    <div class="calendar" id="shifts">      <div class="calendar-header">        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">          <ChevronLeftIcon class="icon" />        </button>        <h3 class="calendar-title" id="shifts-title" aria-live="polite"></h3>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">          <ChevronRightIcon class="icon" />        </button>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="shifts-title"></div>    </div>  </div></template>
平日をクリックして選択を切り替えます。週末は選択できません。

min、max、disabled は、1 日を選ぶ場合と同じように機能します。range も指定した場合は、range が優先されます。

#複数の月

2 か月を横に並べると、月をまたぐ期間を表示できます。各月は、それぞれのヘッダーとグリッドを持つ calendar-month です。最初のヘッダーに前の月へのボタン、最後のヘッダーに次の月へのボタンを置き、各タイトルはそれぞれのグリッドの上に配置します。ビヘイビアは各月を順に埋め、ボタンですべての月を 1 か月ずつまとめて切り替えます。

2 か月

<div class="sheet p-md">  <div class="calendar" id="trip">    <div class="calendar-month">      <div class="calendar-header">        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">          <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />          </svg>        </button>        <h3 class="calendar-title" id="trip-first" aria-live="polite"></h3>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="trip-first"></div>    </div>    <div class="calendar-month">      <div class="calendar-header">        <h3 class="calendar-title" id="trip-second" aria-live="polite"></h3>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">          <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />          </svg>        </button>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="trip-second"></div>    </div>  </div></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.calendar(document.getElementById('trip'), { range: true, value: ['2026-11-26', '2026-12-04'] })})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach, calendar } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => {    const detach = [      attach(root.current!),      calendar(document.getElementById('trip')!, { range: true, value: ['2026-11-26', '2026-12-04'] }),    ]    return () => detach.forEach(stop => stop())  }, [])  return (    <div ref={root} className="sheet p-md">      <div className="calendar" id="trip">        <div className="calendar-month">          <div className="calendar-header">            <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Previous month">              <ChevronLeftIcon className="icon" />            </button>            <h3 className="calendar-title" id="trip-first" aria-live="polite"></h3>          </div>          <div className="calendar-grid" role="grid" aria-labelledby="trip-first"></div>        </div>        <div className="calendar-month">          <div className="calendar-header">            <h3 className="calendar-title" id="trip-second" aria-live="polite"></h3>            <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Next month">              <ChevronRightIcon className="icon" />            </button>          </div>          <div className="calendar-grid" role="grid" aria-labelledby="trip-second"></div>        </div>      </div>    </div>  )}
<script>  import { attach, calendar } from '@master/ui/behaviors'  import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left'  import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'  function mounted(root) {    const detach = [      attach(root),      calendar(document.getElementById('trip'), { range: true, value: ['2026-11-26', '2026-12-04'] }),    ]    return () => detach.forEach(stop => stop())  }</script><div class="sheet p-md" {@attach mounted}>  <div class="calendar" id="trip">    <div class="calendar-month">      <div class="calendar-header">        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">          <ChevronLeftIcon class="icon" />        </button>        <h3 class="calendar-title" id="trip-first" aria-live="polite"></h3>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="trip-first"></div>    </div>    <div class="calendar-month">      <div class="calendar-header">        <h3 class="calendar-title" id="trip-second" aria-live="polite"></h3>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">          <ChevronRightIcon class="icon" />        </button>      </div>      <div class="calendar-grid" role="grid" aria-labelledby="trip-second"></div>    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, calendar } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'const root = ref(null)let detach = []onMounted(() => {  detach = [    attach(root.value),    calendar(document.getElementById('trip'), { range: true, value: ['2026-11-26', '2026-12-04'] }),  ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template>  <div ref="root" class="sheet p-md">    <div class="calendar" id="trip">      <div class="calendar-month">        <div class="calendar-header">          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">            <ChevronLeftIcon class="icon" />          </button>          <h3 class="calendar-title" id="trip-first" aria-live="polite"></h3>        </div>        <div class="calendar-grid" role="grid" aria-labelledby="trip-first"></div>      </div>      <div class="calendar-month">        <div class="calendar-header">          <h3 class="calendar-title" id="trip-second" aria-live="polite"></h3>          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">            <ChevronRightIcon class="icon" />          </button>        </div>        <div class="calendar-grid" role="grid" aria-labelledby="trip-second"></div>      </div>    </div>  </div></template>
2 か月にまたがる期間を選ぶか、矢印キーで前の月から次の月へ移動します。

複数の月は 1 つのタブストップとひと続きのキー操作を共有します。最初の月の最終日から矢印キーを押すと次の月の 1 日に移り、最後の月を越えて移動すると両方の月が切り替わります。月の範囲外の日付は空欄になります。隣の月にその日付が表示されるためです。空欄によって曜日の列は保たれます。行に十分な幅がない場合、月は縦に並びます。

#日付ピッカー

日付ピッカーは、入力フィールド、ボタン、ポップオーバー 内のカレンダーで構成します。ポップオーバーはスクリプトなしで開閉し、ボタンを基準に自動で配置されます。ビヘイビアはカレンダーを描画し、選択された日付を通知します。ページ側のスクリプトはその日付をフィールドに書き込み、ポップオーバーを閉じます。

日付ピッカー

<div class="field max-w(280) mx-auto">  <label for="starts">Starts</label>  <div class="input-group">    <input class="input-group-field" id="starts" value="2026-11-04" readonly>    <button type="button" class="btn btn-quiet btn-square" popovertarget="starts-calendar" aria-label="Choose a date">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <rect x="2.5" y="3.5" width="11" height="10.5" rx="1" /><path d="M2.5 6.5L13.5 6.5" /><path d="M5.5 2L5.5 4.5" /><path d="M10.5 2L10.5 4.5" /><circle cx="6" cy="9.5" r="0.5" fill="currentColor" stroke="none" /><circle cx="10" cy="9.5" r="0.5" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="0.5" fill="currentColor" stroke="none" />      </svg>    </button>    <div id="starts-calendar" popover class="popover popover-end">      <div class="calendar">        <div class="calendar-header">          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous month">            <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />            </svg>          </button>          <h3 class="calendar-title" id="picker-title" aria-live="polite"></h3>          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next month">            <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />            </svg>          </button>        </div>        <div class="calendar-grid" role="grid" aria-labelledby="picker-title"></div>      </div>    </div>  </div></div><script>addEventListener('DOMContentLoaded', function () {var popover = document.getElementById('starts-calendar')MasterUI.calendar(popover.querySelector('.calendar'), { value: '2026-11-04' })popover.addEventListener('change', function (event) {  document.getElementById('starts').value = event.detail.value  popover.hidePopover()})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>

カレンダーの change イベントはバブリングするため、リスナーはポップオーバーに登録します。イベントの detail.value には YYYY-MM-DD 形式の日付が入ります。これはフォームが日付の値として受け取る形式と同じです。

スマートフォンで使う場合や、フォームで日付を入力できれば十分な場合は、ネイティブの <input type="date"> を使うと、端末標準の日付ピッカーを利用できます。

#ビヘイビア

calendar はルート要素とオプションオブジェクトを受け取り、ビヘイビアの適用を解除する関数を返します。

app.js
import { calendar } from '@master/ui/behaviors/calendar.js'const root = document.querySelector('.calendar')const picker = calendar(root, { value: '2026-11-04', min: '2026-11-01', max: '2026-12-31' })root.addEventListener('change', (event) => console.log(event.detail.value))
オプション設定内容
valueYYYY-MM-DD 形式の選択日、期間の開始日と終了日、または multiple で選択した日付
month最初に表示する月を YYYY-MM 形式で指定。既定は値が属する月、値がなければ今月
min, max選択可能な最初と最後の日付を YYYY-MM-DD 形式で指定。移動先の月がなければ、対応する月切り替えボタンは無効
rangetrue を指定すると、2 つの日付を選んで、その間のすべての日付を含む期間を選択できます。
multipletrue を指定すると、任意の数の離れた日付を選択できます。range のほうが優先されます。
labels月と年の一覧で使う月切り替えボタンの名前:previousYear、nextYear、previousDecade、nextDecade。既定は英語
weekStart最初の列の曜日。日曜の 0 から土曜の 6 まで。既定はロケールの週の開始曜日で、ブラウザーから取得できない場合は月曜
locale月名と曜日名に使う BCP 47 言語タグ。既定はカレンダーに適用される lang 属性の値
disabledDate を受け取り、その日付が選択不可かどうかを返す関数
drawスクリプトに代わってグリッドを生成する関数。表示する月が YYYY-MM 形式で、表示の種類が days、months、years のいずれかで渡されます。日付の表示では、その月と、続くグリッドにはその後の月を書き込みます。各月は calendarMonth(month, { offset }) で取得できます。月や年の表示では、calendarPeriods(month, { view }) が返すセルを書き込みます。独自のグリッド を参照してください。
  • 生成する内容。 曜日名、表示する各月の週ごとの日付、各月の名前を書き込みます。月や年へ移動した表示では、月や年とそのタイトルを書き込みます。日付ボタンでは、value に日付を設定し、今日には aria-current="date"、選択された日付には aria-selected="true" と期間用のクラス、選択できない日付には disabled を設定します。さらに、aria-label に完全な日付を指定し、tabindex でタブ順に含まれる日付を 1 つに絞ります。draw を指定した場合は、テンプレートやフレームワークが日付ボタンを生成し、スクリプトは状態などの属性やクラスだけを設定します。
  • イベント。 日付を選択すると、ルートからバブリングする input と change がこの順に発行されます。どちらのイベントでも、detail.value には、単一選択なら YYYY-MM-DD 形式の日付、期間選択なら両端を選び終えた時点で [start, end]、multiple なら日付順に並べたリストが入ります。期間の 1 つ目の端を選んだときは input だけが発行され、値は [start, null] になります。値は変わっていますが、2 つ目の端を選ぶまで期間は完成しません。月や年の表示への移動ではイベントは発行されません。
  • 値。 値の保持先はスクリプト内です。返された関数の value から、picker.value のように読み取ります。期間の終了日は、選択されるまで null です。multiple で何も選択されていない場合は [] です。外部から選択を変更するには値を設定します。picker.value = '2026-11-20' は新しく選んだ日付が属する月を表示し、イベントは発行しません。
  • 日付。 ローカルのタイムゾーンとグレゴリオ暦に従います。

#構造

  • calendar-grid で 7 列を一度だけ定義します。各 calendar-week はその列を引き継ぐサブグリッド上の行なので、テーブルを使わずに曜日名と日付の列を揃えられます。
  • calendar-weekday は列見出しです。aria-label には省略していない曜日名を指定します。
  • calendar-day は、role="gridcell" を持つ <button> です。
  • calendar-title-button は、タイトルにボタンがある場合に calendar-title 内に置く <button> です。ビヘイビアがタイトルをこのボタンに書き込みます。
  • calendar-period は、移動先の一覧に表示される月や年です。role="gridcell" を持つ <button> で、値は YYYY-MM または YYYY です。1 つの calendar-week に 3 つずつ並びます。
  • calendar-month は、複数の月のうち 1 か月分のヘッダーとグリッドを含みます。

#キーボード操作

ビヘイビアは、日付グリッドのキーボード操作を提供します。月の境界を越えて移動すると、隣の月が表示され、移動先の日付にフォーカスが移ります。選択できない日付は飛ばし、min と max の境界で移動が止まります。月と年の一覧では、矢印キーで 1 つずつ、または 3 つ並んだ 1 行分ずつ移動し、Enter で選択して 1 つ下の階層に戻ります。

キー操作
ArrowLeft, ArrowRight前日または翌日にフォーカスを移動します。右から左に並ぶ場合は方向が逆になります。月の最終日からは翌月の初日に移動し、複数の月を表示している場合は隣のグリッドに移ります。月や年の表示では前後の月または年に移動します。
ArrowUp, ArrowDown前週または翌週の同じ曜日にフォーカスを移動します。月や年の表示では、上または下の行にある3つ前または3つ後の項目に移動します。
Home, End週の最初または最後の日にフォーカスを移動します。月や年の表示では、行の最初または最後の項目に移動します。
PageUp, PageDown前月または翌月を表示し、その月の同じ日にフォーカスを移動します。その月のほうが短い場合は月末日に移動します。月や年の表示では、前後の年または前後の10年を表示します。
Shift+PageUp, Shift+PageDown前年または翌年の同じ月を表示し、その月の同じ日付にフォーカスを移動します。
Enter, Spaceフォーカスのある日を選択します。multiple の場合は選択のオンとオフを切り替えます。月や年では、その月の日またはその年の月を表示します。セルはボタンなので、ブラウザーがキー操作をクリックに変換します。
Escape月や年の表示では日の表示に戻り、元の日にフォーカスを戻します。日の表示では、ポップオーバーなどカレンダーを収める側の処理に任せます。
TabTab キーでグリッドに入ると、選択日(複数あれば最初の日)にフォーカスします。選択日がなければ今日に、表示中の月にどちらも含まれなければ表示中の最初の月の初日にフォーカスします。複数の月のグリッドはまとめて 1 つのタブストップです。

#アクセシビリティ

  • グリッドには role="grid" を指定し、月のタイトルをラベルにします。各週には role="row" を指定します。
  • タブ順に含まれる日付は 1 つです。選択済みの日付(複数ある場合は最初の日付)があればその日、なければ今日を使い、表示中の月がどちらも含まない場合は表示中の月の 1 日を使います。ほかの日付には tabindex="-1" を指定します。横に並んだ複数の月は全体で 1 つのタブストップになり、各グリッドはそれぞれのタイトルをラベルにします。
  • 期間や複数の日付を選択できるグリッドには、aria-multiselectable="true" を指定します。
  • タイトルボタンの名前は、ボタンに表示されるタイトルです。これはグリッドのラベルにもなります。ボタンで何ができるかは、「月または年を選択」のように aria-description で伝えてください。aria-label を使うと、グリッドの名前も変わってしまいます。
  • 月の切り替えが読み上げられるよう、タイトルに aria-live="polite" を指定します。
  • タッチスクリーンでも、日付ボタンは 36px のままです。グリッドは月表示の形を保ち、日付ボタンにも指で操作するのに十分な大きさがあります。
  • カレンダーの近くで日付の意味を伝えます。「週末は休業」のように選べない日の理由や、範囲ならチェックイン日とチェックアウト日のように両端が何を表すかです。無効な日やインクで塗られた端だけでは、どちらも伝わりません。

#React、Svelte、Vue

calendar コンポーネントは、ビヘイビアと同じデータから月の表示を生成するため、最初の HTML にカレンダーが含まれます。選択日は外部から受け取り、選択の変更を外部に通知します。range では値が 2 回通知されます。1 つ目の端を選んだときは [start, null]、2 つ目の端を選んだときは [start, end] です。range と multiple を受け取り、months で複数の月を横に並べます。1 か月を表示するときはタイトルボタンを持ちます。jumpLabel はボタンの説明、labels は月と年の一覧で使う月切り替えボタンの名前です。npx master-ui add calendar でプロジェクトにコピーできます。構成と使い方は React、Svelte、Vue を参照してください。

ui/calendar.tsx
'use client'import { Fragment, useId, useMemo, useState, type ComponentProps } from 'react'import { calendar, calendarMonth, calendarPeriods, type CalendarLabels, type CalendarView } from '@master/ui/behaviors/calendar.js'import { useBehavior } from './use-behavior'/** A day as `YYYY-MM-DD`; in a range, its two ends, the second null until it is chosen; with `multiple`, the days chosen, sorted. */export type CalendarValue = string | [string, string | null] | string[] | nullexport interface CalendarProps extends Omit<ComponentProps<'div'>, 'defaultValue' | 'children' | 'ref'> {  value?: CalendarValue  defaultValue?: CalendarValue  onValueChange?: (value: CalendarValue) => void  /** Choose two days and every day between them. */  range?: boolean  /** Choose any number of separate days; the value is their list. `range` wins over it. */  multiple?: boolean  /** How many months to show side by side, 1 by default. A calendar of one month has a title that jumps to the months and the years. */  months?: number  /** The first and the last day that can be chosen, as `YYYY-MM-DD`. */  min?: string  max?: string  /** The month to show first, as `YYYY-MM`. The month of the value, or this month, by default. */  month?: string  /** The day in the first column, 0 for Sunday to 6 for Saturday. The locale's own by default. */  weekStart?: number  /** A BCP 47 tag for the names. Give it when the calendar is rendered on a server, so both sides agree. */  locale?: string  /** Says whether a day cannot be chosen. */  disabled?: (date: Date) => boolean  previousLabel?: string  nextLabel?: string  /** What the title button does, said to assistive technology. */  jumpLabel?: string  /** The names of the month buttons while the grid shows months or years. */  labels?: CalendarLabels}/** * A calendar. React writes the months, from the same data the behavior uses, so they are in the first HTML; * the behavior marks today, the chosen days and the day in the tab order, and asks for other months, or for * the months of a year or the years of a decade when the title jumps. */export function Calendar({ value, defaultValue, onValueChange, range, multiple, months = 1, min, max, month, weekStart, locale, disabled, previousLabel = 'Previous month', nextLabel = 'Next month', jumpLabel = 'Choose a month or a year', labels, className, ...root }: CalendarProps) {  const id = useId()  const [first] = useState(value ?? defaultValue)  const [shown, setShown] = useState(() => calendarMonth(month, { value: first }).month)  const [view, setView] = useState<CalendarView>('days')  const count = Math.max(1, Math.floor(months))  // The first value's days are marked in the first render; after that the behavior marks what is chosen.  const grids = useMemo(() => Array.from({ length: count }, (_, offset) => calendarMonth(shown, { weekStart, locale, value: first, range, multiple, offset })), [count, shown, weekStart, locale, first, range, multiple])  const periods = view === 'days' ? null : calendarPeriods(shown, { view, locale })  const ref = useBehavior(calendar, {    value: (first ?? undefined) as string | string[] | undefined,    range,    multiple,    min,    max,    month,    weekStart,    locale,    disabled,    labels,    draw: (next: string, nextView: CalendarView) => { setShown(next); setView(nextView) },  }, { value, onValueChange })  const several = range || multiple || undefined  const previous = (    <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label={previousLabel}>      <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" /></svg>    </button>  )  const next = (    <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label={nextLabel}>      <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" /></svg>    </button>  )  return (    <div className={className ? `calendar ${className}` : 'calendar'} ref={ref} {...root}>      {grids.map((data, index) => {        const one = count === 1        const title = `${id}title${index}`        const header = (          <div className="calendar-header">            {index === 0 && previous}            <h3 className="calendar-title" id={title} aria-live="polite">              {one ? <button type="button" className="calendar-title-button" aria-description={jumpLabel}>{periods?.title ?? data.title}</button> : data.title}            </h3>            {index === count - 1 && next}          </div>        )        const grid = (          <div className="calendar-grid" role="grid" aria-labelledby={title} aria-multiselectable={several}>            {one && periods              ? periods.rows.map(row => (                  <div className="calendar-week" role="row" key={row[0]!.value}>                    {row.map(cell => <button type="button" className={cell.outside ? 'calendar-period calendar-period-outside' : 'calendar-period'} role="gridcell" tabIndex={-1} value={cell.value} aria-label={cell.label} key={cell.value}>{cell.text}</button>)}                  </div>                ))              : (                  <>                    <div className="calendar-week" role="row">                      {data.weekdays.map(weekday => <span className="calendar-weekday" role="columnheader" aria-label={weekday.name} key={weekday.name}>{weekday.short}</span>)}                    </div>                    {data.weeks.map(week => (                      <div className="calendar-week" role="row" key={week[0]!.date}>                        {week.map(day => <button type="button" className={['calendar-day', day.outside && 'calendar-day-outside', day.range].filter(Boolean).join(' ')} role="gridcell" tabIndex={day.tab ? 0 : -1} value={day.date} aria-selected={day.selected || undefined} aria-label={day.label} key={day.date}>{day.text}</button>)}                      </div>                    ))}                  </>                )}          </div>        )        // One month is a header and a grid. Each of several is a calendar-month, which keeps its place, so the        // button in its header keeps focus while the months turn.        return one ? <Fragment key={index}>{header}{grid}</Fragment> : <div className="calendar-month" key={index}>{header}{grid}</div>      })}    </div>  )}
ui/Calendar.svelte
<script lang="ts" module>  import type { HTMLAttributes } from 'svelte/elements'  import type { CalendarLabels } from '@master/ui/behaviors/calendar.js'  /** A day as `YYYY-MM-DD`; in a range, its two ends, the second null until it is chosen; with `multiple`, the days chosen, sorted. */  export type CalendarValue = string | [string, string | null] | string[] | null  export interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {    /** What is chosen. Bind it, or leave it out and the pattern keeps its own. */    value?: CalendarValue    onValueChange?: (value: CalendarValue) => void    /** Choose two days and every day between them. */    range?: boolean    /** Choose any number of separate days; the value is their list. `range` wins over it. */    multiple?: boolean    /** How many months to show side by side, 1 by default. A calendar of one month has a title that jumps to the months and the years. */    months?: number    /** The first and the last day that can be chosen, as `YYYY-MM-DD`. */    min?: string    max?: string    /** The month to show first, as `YYYY-MM`. The month of the value, or this month, by default. */    month?: string    /** The day in the first column, 0 for Sunday to 6 for Saturday. The locale's own by default. */    weekStart?: number    /** A BCP 47 tag for the names. Give it when the calendar is rendered on a server, so both sides agree. */    locale?: string    /** Says whether a day cannot be chosen. */    disabled?: (date: Date) => boolean    previousLabel?: string    nextLabel?: string    /** What the title button does, said to assistive technology. */    jumpLabel?: string    /** The names of the month buttons while the grid shows months or years. */    labels?: CalendarLabels  }</script><script lang="ts">  import { untrack } from 'svelte'  import { calendar, calendarMonth, calendarPeriods, type CalendarMonth, type CalendarView } from '@master/ui/behaviors/calendar.js'  import { behavior } from './behavior.svelte.js'  let { value = $bindable(), onValueChange, range, multiple, months = 1, min, max, month, weekStart, locale, disabled, previousLabel = 'Previous month', nextLabel = 'Next month', jumpLabel = 'Choose a month or a year', labels, class: className, ...root }: CalendarProps = $props()  const id = $props.id()  const first = untrack(() => value)  let shown = $state(untrack(() => calendarMonth(month, { value: first }).month))  let view = $state<CalendarView>('days')  const count = $derived(Math.max(1, Math.floor(months)))  // The first value's days are marked in the first render; after that the behavior marks what is chosen.  const grids = $derived(Array.from({ length: count }, (_, offset) => calendarMonth(shown, { weekStart, locale, value: first, range, multiple, offset })))  const periods = $derived(view === 'days' ? null : calendarPeriods(shown, { view, locale }))  const several = $derived(range || multiple || undefined)  const attach = behavior(calendar, () => ({    value: (first ?? undefined) as string | string[] | undefined,    range,    multiple,    min,    max,    month,    weekStart,    locale,    disabled,    labels,    draw: (next: string, nextView: CalendarView) => { shown = next; view = nextView },  }), {    value: () => value,    change: (next) => { value = next; onValueChange?.(next) },  })</script><!--  @component  A calendar. Svelte writes the months, from the same data the behavior uses, so they are in the first HTML;  the behavior marks today, the chosen days and the day in the tab order, and asks for other months, or for  the months of a year or the years of a decade when the title jumps.-->{#snippet previous()}  <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label={previousLabel}>    <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" /></svg>  </button>{/snippet}{#snippet next()}  <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label={nextLabel}>    <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" /></svg>  </button>{/snippet}{#snippet days(data: CalendarMonth)}  <div class="calendar-week" role="row">    {#each data.weekdays as weekday (weekday.name)}      <span class="calendar-weekday" role="columnheader" aria-label={weekday.name}>{weekday.short}</span>    {/each}  </div>  {#each data.weeks as week (week[0]!.date)}    <div class="calendar-week" role="row">      {#each week as day (day.date)}        <button type="button" class={['calendar-day', day.outside && 'calendar-day-outside', day.range]} role="gridcell" tabindex={day.tab ? 0 : -1} value={day.date} aria-selected={day.selected || undefined} aria-label={day.label}>{day.text}</button>      {/each}    </div>  {/each}{/snippet}<div class={['calendar', className]} {@attach attach} {...root}>  {#if count > 1}    <!-- A month keeps its place, so the button in its header keeps focus while the months turn. -->    {#each grids as data, index (index)}      <div class="calendar-month">        <div class="calendar-header">          {#if index === 0}{@render previous()}{/if}          <h3 class="calendar-title" id="{id}title{index}" aria-live="polite">{data.title}</h3>          {#if index === count - 1}{@render next()}{/if}        </div>        <div class="calendar-grid" role="grid" aria-labelledby="{id}title{index}" aria-multiselectable={several}>          {@render days(data)}        </div>      </div>    {/each}  {:else}    <div class="calendar-header">      {@render previous()}      <!-- aria-description is an ARIA 1.3 attribute of every role, which Svelte's element types do not know yet. -->      <h3 class="calendar-title" id="{id}title" aria-live="polite"><button type="button" class="calendar-title-button" {...{ 'aria-description': jumpLabel }}>{periods?.title ?? grids[0]!.title}</button></h3>      {@render next()}    </div>    <div class="calendar-grid" role="grid" aria-labelledby="{id}title" aria-multiselectable={several}>      {#if periods}        {#each periods.rows as row (row[0]!.value)}          <div class="calendar-week" role="row">            {#each row as cell (cell.value)}              <button type="button" class={cell.outside ? 'calendar-period calendar-period-outside' : 'calendar-period'} role="gridcell" tabindex={-1} value={cell.value} aria-label={cell.label}>{cell.text}</button>            {/each}          </div>        {/each}      {:else}        {@render days(grids[0]!)}      {/if}    </div>  {/if}</div>
ui/Calendar.vue
<script lang="ts">/** A day as `YYYY-MM-DD`; in a range, its two ends, the second null until it is chosen; with `multiple`, the days chosen, sorted. */export type CalendarValue = string | [string, string | null] | string[] | null</script><script setup lang="ts">import { computed, shallowRef, useId, useTemplateRef } from 'vue'import { calendar, calendarMonth, calendarPeriods, type CalendarLabels, type CalendarView } from '@master/ui/behaviors/calendar.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { range, multiple, months = 1, min, max, month, weekStart, locale, disabled, previousLabel = 'Previous month', nextLabel = 'Next month', jumpLabel = 'Choose a month or a year', labels } = defineProps<{  /** Choose two days and every day between them. */  range?: boolean  /** Choose any number of separate days; the value is their list. `range` wins over it. */  multiple?: boolean  /** How many months to show side by side, 1 by default. A calendar of one month has a title that jumps to the months and the years. */  months?: number  /** The first and the last day that can be chosen, as `YYYY-MM-DD`. */  min?: string  max?: string  /** The month to show first, as `YYYY-MM`. The month of the value, or this month, by default. */  month?: string  /** The day in the first column, 0 for Sunday to 6 for Saturday. The locale's own by default. */  weekStart?: number  /** A BCP 47 tag for the names. Give it when the calendar is rendered on a server, so both sides agree. */  locale?: string  /** Says whether a day cannot be chosen. */  disabled?: (date: Date) => boolean  previousLabel?: string  nextLabel?: string  /** What the title button does, said to assistive technology. */  jumpLabel?: string  /** The names of the month buttons while the grid shows months or years. */  labels?: CalendarLabels}>()/** The chosen day, the two ends of a range, or the days chosen with `multiple`: `v-model`. */const model = defineModel<CalendarValue>()/* * A calendar. Vue writes the months, from the same data the behavior uses, so they are in the first HTML; * the behavior marks today, the chosen days and the day in the tab order, and asks for other months, or for * the months of a year or the years of a decade when the title jumps. */const id = useId()const first = model.valueconst shown = shallowRef(calendarMonth(month, { value: first }).month)const view = shallowRef<CalendarView>('days')const count = computed(() => Math.max(1, Math.floor(months)))// The first value's days are marked in the first render; after that the behavior marks what is chosen.const grids = computed(() => Array.from({ length: count.value }, (_, offset) => calendarMonth(shown.value, { weekStart, locale, value: first, range, multiple, offset })))const periods = computed(() => (view.value === 'days' ? null : calendarPeriods(shown.value, { view: view.value, locale })))const several = computed(() => range || multiple || undefined)const root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, calendar, () => ({  value: (first ?? undefined) as string | string[] | undefined,  range,  multiple,  min,  max,  month,  weekStart,  locale,  disabled,  labels,  draw: (next: string, nextView: CalendarView) => {    shown.value = next    view.value = nextView  },}), model)</script><template>  <div ref="root" class="calendar" v-bind="$attrs">    <template v-if="count > 1">      <div v-for="(data, index) in grids" :key="index" class="calendar-month">        <div class="calendar-header">          <button v-if="index === 0" type="button" class="btn btn-quiet btn-square btn-sm" :aria-label="previousLabel">            <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" /></svg>          </button>          <h3 :id="`${id}-title-${index}`" class="calendar-title" aria-live="polite">{{ data.title }}</h3>          <button v-if="index === count - 1" type="button" class="btn btn-quiet btn-square btn-sm" :aria-label="nextLabel">            <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" /></svg>          </button>        </div>        <div class="calendar-grid" role="grid" :aria-labelledby="`${id}-title-${index}`" :aria-multiselectable="several">          <div class="calendar-week" role="row">            <span v-for="weekday in data.weekdays" :key="weekday.name" class="calendar-weekday" role="columnheader" :aria-label="weekday.name">{{ weekday.short }}</span>          </div>          <div v-for="week in data.weeks" :key="week[0]!.date" class="calendar-week" role="row">            <button v-for="day in week" :key="day.date" type="button" class="calendar-day" :class="[{ 'calendar-day-outside': day.outside }, day.range]" role="gridcell" :tabindex="day.tab ? 0 : -1" :value="day.date" :aria-selected="day.selected || undefined" :aria-label="day.label">{{ day.text }}</button>          </div>        </div>      </div>    </template>    <template v-else>      <div class="calendar-header">        <button type="button" class="btn btn-quiet btn-square btn-sm" :aria-label="previousLabel">          <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" /></svg>        </button>        <h3 :id="`${id}-title`" class="calendar-title" aria-live="polite"><button type="button" class="calendar-title-button" :aria-description="jumpLabel">{{ periods?.title ?? grids[0]!.title }}</button></h3>        <button type="button" class="btn btn-quiet btn-square btn-sm" :aria-label="nextLabel">          <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="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" /></svg>        </button>      </div>      <div class="calendar-grid" role="grid" :aria-labelledby="`${id}-title`" :aria-multiselectable="several">        <template v-if="periods">          <div v-for="row in periods.rows" :key="row[0]!.value" class="calendar-week" role="row">            <button v-for="cell in row" :key="cell.value" type="button" class="calendar-period" :class="{ 'calendar-period-outside': cell.outside }" role="gridcell" :tabindex="-1" :value="cell.value" :aria-label="cell.label">{{ cell.text }}</button>          </div>        </template>        <template v-else>          <div class="calendar-week" role="row">            <span v-for="weekday in grids[0]!.weekdays" :key="weekday.name" class="calendar-weekday" role="columnheader" :aria-label="weekday.name">{{ weekday.short }}</span>          </div>          <div v-for="week in grids[0]!.weeks" :key="week[0]!.date" class="calendar-week" role="row">            <button v-for="day in week" :key="day.date" type="button" class="calendar-day" :class="[{ 'calendar-day-outside': day.outside }, day.range]" role="gridcell" :tabindex="day.tab ? 0 : -1" :value="day.date" :aria-selected="day.selected || undefined" :aria-label="day.label">{{ day.text }}</button>          </div>        </template>      </div>    </template>  </div></template>

#クラス

クラス説明
calendarカレンダー本体です。グリッドの上にヘッダーを置くか、複数の月を横に並べる場合は月ごとに calendar-month を置きます。
calendar-month横に並べた複数の月のうちの1か月分で、独自の calendar-header と calendar-grid を持ちます。月の範囲外の日は隣の月に表示されるため空白にします。行に収まらない場合、月は縦の列に折り返します。
calendar-headerグリッドの上に置く行です。前月ボタン、タイトル、翌月ボタンの順に並びます。複数の月を表示する場合は、最初の月のヘッダーに前月ボタン、最後の月のヘッダーに翌月ボタンを置きます。
calendar-title2 つのボタンの間に中央揃えで表示する月名です。月の切り替えが読み上げられるように aria-live="polite" を付けます。calendar-title-button を含めることもできます。
calendar-title-button1か月表示のカレンダーで、タイトルをボタンにします。押すとグリッドにその年の12か月を表示し、さらに押すと10年分の年を表示します。年の表示ではボタンは無効になります。タイトルの文字列はビヘイビアがボタンに書き込みます。
calendar-gridrole="grid" を指定した 7 列のグリッドです。タイトルをグリッドのラベルにします。範囲または複数の日を選べる場合は aria-multiselectable="true" を付けます。月や年の表示では 3 列になります。
calendar-weekグリッドの列に沿った行で、role="row" を付けます。曜日名、1週間分の日、または3つの月や年を並べます。
calendar-weekdayrole="columnheader" を指定した列見出しです。aria-label には省略していない曜日名を指定します。
calendar-day日付をrole="gridcell"付きのボタンで表示します。Tab順に入るのは1日だけで、ほかの日にはtabindex="-1"を付けます。ボタンの値はYYYY-MM-DD形式の日付です。ビヘイビアが値を書き込み、ほかの処理が値を設定した日付ボタンからはその値を読み取ります。
calendar-day-outside週を埋めるために控えめなインク色で表示する前月または翌月の日calendar-day と併用します
calendar-day-range-start範囲の初日。範囲側の半分に帯を敷き、日付はインク色で表示します。同じ日に calendar-day-range-end も指定すると、1 日だけの範囲になります。calendar-day と併用します
calendar-day-range範囲の開始日と終了日の間にある日です。チップと同系色の帯がセル間をつなぎ、週の端で丸くなります。calendar-day と併用します
calendar-day-range-end範囲の最終日です。セルの範囲側の半分に帯を敷き、日付はインク色で表示します。calendar-day と併用します
calendar-periodタイトルから移動したグリッドに表示する月または年です。role="gridcell" を付けたボタンに置き、日と同じ質感で描画します。4行で6週分と同じ高さになります。値は月なら YYYY-MM、年なら YYYY です。
calendar-period-outside10年の前後の年です。行を埋めるために控えめなインク色で表示します。calendar-period と併用します

#カスタムプロパティ

プロパティ既定値説明
--calendar-cell2.25rem日付セルの幅と高さです。すでに指での操作に必要な大きさを上回っています。
--calendar-day-radiusvar(--radius-control-sm)日付セルの角の丸み

#ソース

@master/ui/components/calendar.css
/* * Calendar: a month of days to pick from, as an ARIA grid of buttons. * The stylesheet draws every state and leaves the dates and the keys to the script that fills it: today is * aria-current="date" and carries a dot, a chosen day is aria-selected and fills with ink the way a checkbox * does, and a range is a chip-toned band between two ink days. Weeks are rows on a subgrid, so the seven * columns are declared once. It has no surface of its own: put it in a popover for a date picker, or a card. * * The title may hold a button that jumps to the months of the year and the years of a decade: they are cells of * the same grid, three to a row, in the day's material, and the grid keeps the height of a six-week month so the * calendar does not jump with it. Several months side by side are a calendar-month each, wrapping to a column * where the row has no room; there the days outside a month are left blank, since the month beside it shows them. */@layer components.ui {  .calendar {    --calendar-cell: 2.25rem;    --calendar-day-radius: var(--radius-control-sm);    /* The width of a month button, which a title with a button on one side only keeps free on the other. */    --calendar-turn: 2rem;    display: inline-grid;    gap: .5rem;    min-width: 0;    color: var(--color-text-strong);    font: 400 .8125rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    user-select: none;    -webkit-user-select: none;  }  /* Several months side by side: a column of them where the row has no room. */  .calendar:has(.calendar-month) {    display: inline-flex;    flex-wrap: wrap;    align-items: flex-start;    gap: 1rem 1.5rem;  }  /* One month of several: its header and its grid. */  .calendar-month {    display: grid;    gap: .5rem;    min-width: 0;    /* A day of the month before or after is shown by that month, so here it only keeps its column. */    & .calendar-day-outside {      visibility: hidden;    }  }  /* Previous, the month, next. */  .calendar-header {    display: flex;    align-items: center;    justify-content: space-between;    gap: .5rem;  }  .calendar-title {    flex: 1 1 0;    margin: 0;    color: var(--color-text-strong);    font: var(--font-weight-control) .875rem/1.4 var(--font-family-sans);    font-feature-settings: inherit;    text-align: center;    /* In a month of several the title may have a month button on one side only; it stays over the middle. */    &:first-child {      margin-inline-start: calc(var(--calendar-turn) + .5rem);    }    &:last-child {      margin-inline-end: calc(var(--calendar-turn) + .5rem);    }  }  /* The title as a button: it shows the months of the year, then the years of the decade. */  .calendar-title-button {    display: inline-flex;    align-items: center;    max-width: 100%;    min-height: 2rem;    margin: 0;    padding: 0 .5rem;    border: 0;    border-radius: calc(var(--calendar-day-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: transparent;    color: inherit;    font: inherit;    font-feature-settings: inherit;    appearance: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    /* Like a day, it answers at once. */    @media (hover: hover) {      &:hover:not(:disabled) {        background: var(--color-surface-chip);      }    }    &:active:not(:disabled) {      background: var(--color-surface-inset-hover);    }    &:focus-visible {      @apply --focus-ring;    }    /* At the decade there is nowhere further to go: it reads as the title it is. */    &:disabled {      cursor: default;    }    /* On touch the target reaches 44px around the title, which keeps its height. */    @media (pointer: coarse) {      position: relative;      &::after {        @apply --touch-target;      }    }  }  /* Seven columns; rows keep 2px apart so a range reads as one band per week. */  .calendar-grid {    display: grid;    grid-template-columns: repeat(7, var(--calendar-cell));    row-gap: 2px;    /* The months or the years: three columns over the same width. */    &:has(.calendar-period) {      grid-template-columns: repeat(3, 1fr);      width: calc(var(--calendar-cell) * 7);      gap: 4px;    }  }  /* A row of the grid: the weekday names, or a week of days, on the grid's own columns. */  .calendar-week {    display: grid;    grid-column: 1 / -1;    grid-template-columns: subgrid;  }  .calendar-weekday {    display: grid;    place-items: center;    height: 1.75rem;    color: var(--color-text-muted);    font-size: .71875rem;    font-weight: 400;  }  /* A day, or a month or a year: a button in a grid cell. */  .calendar-day, .calendar-period {    position: relative;    isolation: isolate;    display: grid;    place-items: center;    width: 100%;    height: var(--calendar-cell);    margin: 0;    padding: 0;    border: 0;    border-radius: calc(var(--calendar-day-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: transparent;    color: inherit;    font: inherit;    font-feature-settings: inherit;    appearance: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    font-variant-numeric: tabular-nums;    /* A day answers at once, like a row in a menu. */    @media (hover: hover) {      &:hover:not(:disabled, [aria-disabled="true"], [aria-selected="true"], [aria-pressed="true"]) {        background: var(--color-surface-chip);      }    }    /* Pressed: a step deeper than the pointer's tone. */    &:active:not(:disabled, [aria-disabled="true"], [aria-selected="true"], [aria-pressed="true"]) {      background: var(--color-surface-inset-hover);    }    /*     * Today keeps its place in the month with a dot under the number. It keeps the weight of every other day, so     * the number is as wide as it is on any other date.     */    &[aria-current="date"] {      &::after {        content: '';        position: absolute;        inset-block-end: .3125rem;        inset-inline-start: calc(50% - 1.5px);        width: 3px;        height: 3px;        border-radius: 999px;        background: currentColor;      }    }    /* A day of the month before or after, shown to complete a week; a year of the decade before or after. */    &.calendar-day-outside, &.calendar-period-outside {      color: var(--color-text-muted);    }    /* Chosen: ink, with the line of light a checked checkbox has. */    &:is([aria-selected="true"], [aria-pressed="true"]) {      background: var(--color-surface-inverse);      color: var(--color-text-inverse);      box-shadow: var(--shadow-ink-mark);    }    /* Inside a range: a chip-toned band that runs from cell to cell, rounded where a week ends. */    &.calendar-day-range {      border-radius: 0;      background: var(--color-surface-chip);      color: var(--color-text-strong);      box-shadow: none;      &:first-child {        border-start-start-radius: calc(var(--calendar-day-radius) * var(--corner-scale));        border-end-start-radius: calc(var(--calendar-day-radius) * var(--corner-scale));      }      &:last-child {        border-start-end-radius: calc(var(--calendar-day-radius) * var(--corner-scale));        border-end-end-radius: calc(var(--calendar-day-radius) * var(--corner-scale));      }    }    /*     * The ends of a range: the band covers the half of the cell that faces the range, and the ink day sits     * on it as a layer of its own, so the band meets the day's middle and not its rounded edge.     */    &:is(.calendar-day-range-start, .calendar-day-range-end) {      --calendar-band: to right;      border-radius: 0;      background: linear-gradient(var(--calendar-band), transparent 50%, var(--color-surface-chip) 0);      color: var(--color-text-inverse);      box-shadow: none;      &::before {        content: '';        position: absolute;        inset: 0;        z-index: -1;        border-radius: calc(var(--calendar-day-radius) * var(--corner-scale));        corner-shape: var(--corner-shape);        background: var(--color-surface-inverse);        box-shadow: var(--shadow-ink-mark);      }      &:dir(rtl) {        --calendar-band: to left;      }    }    &.calendar-day-range-end {      --calendar-band: to left;      &:dir(rtl) {        --calendar-band: to right;      }    }    /* A range of one day has no band, and a range that ends a week does not run past it. */    &.calendar-day-range-start:is(.calendar-day-range-end, :last-child), &.calendar-day-range-end:first-child {      background: none;    }    &:focus-visible {      @apply --focus-ring;      z-index: 1;    }    &:is(:disabled, [aria-disabled="true"]) {      color: var(--color-text-disabled);      cursor: not-allowed;    }    @media (forced-colors: active) {      /*       * A button marked aria-disabled is not one the platform knows to grey: it is given the system's disabled ink.       * A chosen day keeps its highlighted text, which the rule after this one gives it.       */      &:is(:disabled, [aria-disabled="true"]) {        color: GrayText;      }      &:is([aria-selected="true"], [aria-pressed="true"], .calendar-day-range-start, .calendar-day-range-end) {        background: Highlight;        color: HighlightText;        forced-color-adjust: none;      }      &.calendar-day-range {        outline: 1px solid Highlight;        outline-offset: -1px;      }      /*       * Focus keeps its ring in the system's color. It follows the band's outline, which would otherwise take its       * place on a day inside a range, and it is given a color because the chosen days opt out of forced colors.       */      &:focus-visible {        outline: 2px solid Highlight;        outline-offset: 2px;      }      &::before {        display: none;      }      /* Today's dot is drawn in the current color, which forced colors would turn to the canvas: it keeps the text's. */      &[aria-current="date"]::after {        forced-color-adjust: none;      }    }  }  /*   * A month or a year: four rows as tall as the weekday names and six weeks, so the grid keeps the height of a   * six-week month.   */  .calendar-period {    height: calc((var(--calendar-cell) * 6 + 1.75rem) / 4);    /* The dot of today's month or year keeps the distance it has under a day's number. */    &[aria-current="date"]::after {      inset-block-end: calc(50% - .8125rem);    }  }}