Calendar
Calendarは、日付を表示または選択するカレンダーのコンポーネントです。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root />
使い方
import { Calendar } from "@yamada-ui/react"
import { Calendar } from "@/components/ui"
import { Calendar } from "@workspaces/ui"
<Calendar.Root />
サイズを変更する
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Wrap gap="md">
<For each={["xs", "sm", "md", "lg", "xl"]}>
{(size, index) => (
<Calendar.Root key={index} size={size} defaultValue={new Date()} />
)}
</For>
</Wrap>
カラースキームを変更する
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Wrap gap="md">
<For each={["success", "warning"]}>
{(colorScheme, index) => (
<Calendar.Root
key={index}
colorScheme={colorScheme}
defaultValue={new Date(new Date().setDate(1))}
/>
)}
</For>
</Wrap>
形を変える
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Wrap gap="md">
<For each={["rounded", "circle", "square"]}>
{(shape, index) => (
<Calendar.Root
key={index}
shape={shape}
range
defaultValue={{
start: new Date(),
end: new Date(new Date().setDate(new Date().getDate() + 4)),
}}
/>
)}
</For>
</Wrap>
フォーマットを変更する
フォーマットを変更する場合は、formatオブジェクトを設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
const format = useMemo<Calendar.Format>(
() => ({
month: "long",
weekday: "narrow",
year: "2-digit",
}),
[],
)
return <Calendar.Root format={format} />
デフォルトの日付を設定する
デフォルトの日付を設定する場合は、defaultValueにDateを設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root defaultValue={new Date()} />
デフォルトの月を設定する
デフォルトの月を設定する場合は、defaultMonthにDateを設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 28 | 29 | 30 | 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | 1 |
<Calendar.Root defaultMonth={new Date("2025-10-01")} />
最小日付を設定する
最小日付を設定する場合は、minDateにDateを設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root minDate={new Date(new Date().setDate(1))} />
最大日付を設定する
最大日付を設定する場合は、maxDateにDateを設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root maxDate={new Date(new Date().setDate(18))} />
無効にする
無効にする場合は、disabledをtrueに設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root disabled />
今日の強調を無効にする
今日の強調を無効にする場合は、todayをfalseに設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root today={false} />
特定の曜日を無効にする
特定の曜日を無効にする場合は、excludeDateに関数を設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root excludeDate={(date) => [0, 1, 6].includes(date.getDay())} />
複数選択を有効にする
複数選択を有効にする場合は、multipleをtrueに設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root multiple />
複数選択の最大数を設定する
複数選択の最大選択数を設定する場合は、maxに数値を設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root multiple max={3} />
期間選択を有効にする
期間選択を有効にする場合は、rangeをtrueに設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root range />
週の開始曜日を変更する
週の開始曜日を変更する場合は、startDayOfWeekに"sunday"または"monday"を設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 月 | 火 | 水 | 木 | 金 | 土 | 日 |
|---|---|---|---|---|---|---|
| 23 | 24 | 25 | 26 | 27 | 28 | 1 |
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 | 1 | 2 | 3 | 4 | 5 |
<Wrap gap="md">
<Calendar.Root startDayOfWeek="sunday" />
<Calendar.Root startDayOfWeek="monday" />
</Wrap>
週末の曜日を変更する
週末の曜日を変更する場合は、weekendDaysに曜日(数値)の配列を設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root weekendDays={[0, 1]} />
祝日を設定する
祝日を設定する場合は、holidaysにDateの配列を設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
const holidays = useMemo(
() => [
new Date("2025-01-01"),
new Date("2025-01-13"),
new Date("2025-02-11"),
new Date("2025-02-23"),
new Date("2025-02-24"),
new Date("2025-03-20"),
new Date("2025-04-29"),
new Date("2025-05-03"),
new Date("2025-05-04"),
new Date("2025-05-05"),
new Date("2025-05-06"),
new Date("2025-07-21"),
new Date("2025-08-11"),
new Date("2025-09-15"),
new Date("2025-09-23"),
new Date("2025-10-13"),
new Date("2025-11-03"),
new Date("2025-11-23"),
new Date("2025-11-24"),
],
[],
)
return <Calendar.Root holidays={holidays} />
当月外の日付を非表示にする
当月外の日付を非表示にする場合は、dayPropsでスタイルを設定します。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Calendar.Root
dayProps={{
css: { "&[data-outside]": { opacity: 0, pointerEvents: "none" } },
}}
/>
コンポーネントをカスタマイズする
コンポーネントをカスタマイズして、表示を変更できます。
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 1 | 2 | 3 | 4 |
<Wrap gap="md">
<Calendar.Root>
<Calendar.Navigation>
<Calendar.Control justifyContent="flex-start" px="3">
{({ month }) =>
`${month.getFullYear()}/${(month.getMonth() + 1).toString().padStart(2, "0")}`
}
</Calendar.Control>
<Calendar.PrevButton gridColumn="6 / 7" />
<Calendar.NextButton gridColumn="7 / 8" />
</Calendar.Navigation>
<Calendar.Month />
</Calendar.Root>
<Calendar.Root
day={({ value }) => (
<Indicator
colorScheme="blue"
size="sm"
disabled={value.getDate() % 4 !== 0}
offset="-3px"
labelProps={{ minBoxSize: "2" }}
>
<Text as="span">{value.getDate()}</Text>
</Indicator>
)}
/>
</Wrap>
制御する
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
const [value, setValue] = useState<Date | undefined>(new Date())
return <Calendar.Root value={value} onChange={setValue} />
"use client"をファイルの上部に追加する必要があります。Props
アクセシビリティ
キーボード操作
| キー | 説明 | 状態 |
|---|---|---|
ArrowUp | フォーカスを上の日付に1つ移動します。 | - |
ArrowDown | フォーカスを下の日付に1つ移動します。 | - |
ArrowLeft | フォーカスを左の日付に1つ移動します。最初の日付の場合は、前の月の最後の日付へ移動します。 | - |
ArrowRight | フォーカスを右の日付に1つ移動します。最後の日付の場合は、次の月の最初の日付へ移動します。 | - |
Home | フォーカスを同じ週の最初の日付へ移動します。 | - |
End | フォーカスを同じ週の最後の日付へ移動します。 | - |
PageUp | フォーカスを前月の日付へ移動します。 | - |
Shift + PageUp | フォーカスを前年の日付へ移動します。 | - |
PageDown | フォーカスを翌月の日付へ移動します。 | - |
Shift + PageDown | フォーカスを翌年の日付へ移動します。 | - |
Space, Enter | フォーカスされた日付の選択状態を切り替えます。 | - |
ARIAロールと属性
| コンポーネント | ロールと属性 | 使い方 |
|---|---|---|
Calendar.YearSelect | aria-label | "年を選択する"を設定します。 |
Calendar.MonthSelect | aria-label | "月を選択する"を設定します。 |
Calendar.Control | role="status" | ステータスであることを示します。 |
aria-live="polite" | フォーカスの外側で更新される可能性があることを示します。 | |
Calendar.Month | role="grid" | グリッドであることを示します。 |
aria-label | "2026年2月"のように、表示されている年月を設定します。 | |
aria-multiselectable | 複数選択または期間選択が可能な場合は"true"を設定します。 | |
Calendar.PrevButton | aria-label | "前の月に移動する"を設定します。 |
Calendar.NextButton | aria-label | "次の月に移動する"を設定します。 |
CalendarDay | aria-label | "2026年2月5日木曜日"のように、日付を設定します。今日の場合は"今日, 2026年2月5日木曜日"を設定します。 |
aria-disabled | 日付が無効な場合は"true"を設定します。 | |
aria-selected | 日付が選択されている場合は"true"を設定します。 |
類似のコンポーネント
Table
Tableは、列のソートや行の選択やクリックイベント機能を備えたテーブルのコンポーネントです。
Stat
Statは、数値やデータをボックス内に表示するために使用されます。
NativeTable
NativeTableは、データを効率的に整理して表示するコンポーネントです。
使用しているコンポーネント・フック
Button
Buttonは、フォームの送信、モーダルの開閉など、ユーザーが操作できるインタラクティブなコンポーネントです。
Field
Fieldは、フォーム要素に、ラベル、ヘルパーメッセージ、エラーメッセージなどをグループ化するために使用されるコンポーネントです。
Icon
Iconは、プロジェクトに使用できる一般的なアイコンコンポーネントです。
Select
Selectは、ユーザーがオプションのリストから値を選択するために使用されるコンポーネントです。
Format
Formatは、日付・数値・バイトなどを特定のロケールに合わせてフォーマットするために使用されます。