Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Calendar examples · Dialog

Calendar with Date and Time in Dialog for React

A button that opens a dialog with a calendar and a time input for picking a date and a time.

Framework
UI library

The date and time calendar inside a Dialog: a Select Date & Time button opens it, with the month on top and the Time field below. Use it when scheduling is one step of a larger form.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How do I read the selected date?

mode="single" makes selected one date and onSelect the setter. This demo stores that date in state, starting from new Date().

How is the time entered?

The time is an Input with type="time" inside a Field. FieldLabel reads Time, value starts at 12:00, and onChange stores event.target.value in its own state. Changing the time leaves the calendar date as it is.

Are the date and the time one value?

date and time are two pieces of state. The calendar updates date, and the input updates time. This demo keeps the hours and minutes on the time state.

How is the input attached to the calendar?

Inside the dialog, a divide-y stack with overflow-hidden, rounded-md and border holds the calendar, then the field. The field has p-4.

How is the dialog opened?

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

What is selected when the dialog calendar renders?

The calendar starts on today, and the time input starts at 12:00. Opening the dialog shows those initial values.