Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Calendar with Range in Dialog for Svelte

A Select Date Range button that opens two months, with the 8th through the 22nd of this month already selected.

UI library: Ark UI

Select Date Range opens a dialog with that title. Two months are shown. The range starts on the 8th through the 22nd of this month, and the second grid is the next month.

Use it when a period is one step, not the whole page. Leave both months visible if people adjust the range often. A Date Picker hides them in a field. In Svelte, Ark UI does not name the start and end.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Calendar anatomy: prev trigger, month select, year select, next trigger, table, table cell

Usage

<Dialog><DialogTrigger>{#snippet asChild(props)}<Button {...props()} variant="outline">Select Date Range</Button>{/snippet}</DialogTrigger><DialogContent class="sm:max-w-fit"><DialogHeader><DialogTitle>Select Date Range</DialogTitle></DialogHeader><Calendar class="rounded-md border" defaultFocusedValue={from} numOfMonths={2} onValueChange={handleValueChange} selectionMode="range" value={value}><CalendarViewControl><CalendarPrevTrigger /><CalendarViewDate /><CalendarNextTrigger /></CalendarViewControl><div class="flex flex-col gap-4 md:flex-row"><CalendarTable><CalendarWeekDays /><CalendarTableDays /></CalendarTable><CalendarTable><CalendarWeekDays /><CalendarTableNextMonth /></CalendarTable></div></Calendar></DialogContent></Dialog>

FAQ

How do I read the start and end dates?

selectionMode="range" makes value the start and end dates, and onValueChange receives { value }. numOfMonths={2} shows two months, and the second CalendarTable uses CalendarTableNextMonth.

Which month is shown first?

defaultFocusedValue is the start date, so the first grid is the month the range starts in. The two tables sit in flex flex-col gap-4 md:flex-row.

How is the dialog opened?

DialogTrigger is a button reading Select Date Range. It opens DialogContent with sm:max-w-fit, and DialogTitle reads Select Date Range.

What range is selected at first?

The 8th through the 22nd of the current month. The dialog opens with that range already set, and the second grid shows the following month.

How are the 8th and the 22nd built?

from and to are parseDate of those two local dates, and value starts as both of them.

How wide is the dialog?

The dialog uses sm:max-w-fit, so the two months set its width. The calendar inside has rounded-md border.

API Reference

Dialog

No extra props in this demo. The rest is on the Dialog page.

Button

Sets props and variant="outline". The rest is on the Button page.

Calendar

Sets defaultFocusedValue={from}, numOfMonths={2}, onValueChange={handleValueChange}, selectionMode="range" and value={value}. The rest is on the Calendar page.