Skip to content

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

Free

Date Picker as Appointment Picker for Svelte

A button that shows today's date. Opening it puts a calendar beside Available Times, from 09:00 AM through 04:30 PM.

UI library: Ark UI

The button shows a calendar icon and today's date. The popover puts a month beside a list labeled Available Times, from 09:00 AM down to 04:30 PM.

Use it to book a date and a slot together. A Calendar alone is enough when there is no time to pick. In Svelte, Ark UI does not know which times are free.

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

Date Picker anatomy: content, prev trigger, next trigger, table cell, trigger, value

Usage

<DatePicker closeOnSelect={false} onValueChange={handleValueChange} positioning={positioning} value={value}><DatePickerTrigger>{#snippet asChild(props)}<Button {...props({ class: "w-70 justify-start font-normal" })} variant="outline"><CalendarIcon aria-hidden="true" data-icon="inline-start" /><span>{label}</span></Button>{/snippet}</DatePickerTrigger><DatePickerContent class="flex divide-x overflow-hidden p-0"><div class="p-3"><CalendarViewControl><CalendarPrevTrigger /><CalendarViewDate /><CalendarNextTrigger /></CalendarViewControl><CalendarTable><CalendarWeekDays /><CalendarTableDays /></CalendarTable></div><div class="relative w-62 overflow-hidden"><div class="absolute inset-0 flex flex-col gap-4"><p class="px-4 pt-4 text-center font-medium text-sm">Available Times</p><ScrollArea class="min-h-0 flex-1"><div class="flex flex-col gap-2 px-4 pb-4">{#each availableTimes as time (time)}<Button onclick={handleTimeClick} size="sm" value={time} variant={selectedTime === time ? "default" : "outline"}>{time}</Button>{/each}</div></ScrollArea></div></div></DatePickerContent></DatePicker>

FAQ

Why doesn't the picker close when I pick a day?

closeOnSelect is false on DatePicker, so it stays open for the time. Escape, a click outside or the button close it.

Where do the time slots come from?

A fixed list of fourteen strings in the file, half-hour steps with a lunch gap. The selected one is a solid button and the rest are outlined. Load the list for the picked day from your booking system to show real availability.

What does the button say?

The date in long form, plus at and the time once a slot is picked, or Pick a date and time with neither. The button prints the value itself, formatted with Intl.DateTimeFormat, so the text needs no date library.

How are the calendar and the slots laid out?

DatePickerContent is a row split by divide-x. The calendar keeps its padding, and the slots column has a fixed width with the Available Times heading and a Scroll Area that fills the calendar's height.

Is the time stored with the date?

No: the date is the picker's value and the time is a separate string. Combine them when you submit, for example into an ISO date-time.

Can I book from the keyboard?

Yes. The arrow keys move through the days and Enter picks one, then Tab reaches the slots, which are buttons.

API Reference

Date Picker

Sets closeOnSelect={false}, onValueChange={handleValueChange}, positioning={positioning} and value={value}. The rest is on the Date Picker page.

Button

Sets props, w-70, justify-start, font-normal, variant="outline" and onclick={handleTimeClick}. The rest is on the Button page.

Calendar

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

Scroll Area

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