Skip to content

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

Free

Calendar with Disabled Dates in Dialog for Svelte

A Select Date button that opens a calendar blocking weekends, the 3rd through the 7th, and the 22nd.

UI library: Ark UI

Select Date opens a dialog with that title. Weekends, the 3rd through the 7th, and the 22nd of this month cannot be picked.

Use it when closed days should be chosen inside a step. Keep the grid on the page if those days are the point of the screen. A Date Picker is the same choice as a field. In Svelte, Ark UI does not decide which days are closed.

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</Button>{/snippet}</DialogTrigger><DialogContent class="sm:max-w-fit"><DialogHeader><DialogTitle>Select Date</DialogTitle></DialogHeader><Calendar class="rounded-md border" isDateUnavailable={isDateUnavailable} onValueChange={handleValueChange} value={value}><CalendarViewControl><CalendarPrevTrigger /><CalendarViewDate /><CalendarNextTrigger /></CalendarViewControl><CalendarTable><CalendarWeekDays /><CalendarTableDays /></CalendarTable></Calendar></DialogContent></Dialog>

FAQ

Which days can't be picked?

isDateUnavailable returns true for Saturday and Sunday, for the 3rd through the 7th, and for the 22nd of the current month.

Why are those dates built from year, month and day?

The unavailable dates are built with parseDate from a local year, month and day, so they carry no time and do not shift with the time zone.

How do I read the selected date?

value is a list holding the selected date, and onValueChange receives { value }. This demo starts the list from parseDate(new Date()).

What happens if someone clicks a disabled day?

That day can't be picked, so the selected date stays on the day already chosen. The rules cover weekends, the 3rd through the 7th, and the 22nd.

How is the dialog opened?

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

Which numbers count as the weekend?

Sunday is 0 and Saturday is 6. The function reads the day of the week and treats 0 and 6 as the weekend.

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 isDateUnavailable={isDateUnavailable}, onValueChange={handleValueChange} and value={value}. The rest is on the Calendar page.