JollyUI
  1. Docs
  2. components
  3. DateField

DateField

A date field allows users to enter and edit date and time values using a keyboard. Each part of a date value is displayed in an individually editable segment.

Birth date
mm
dd
yyyy

Installation

A date field can be built using <input type="date">, but this is very limited in functionality, lacking in internationalization capabilities, inconsistent between browsers, and difficult to style. DateField helps achieve accessible and international date and time fields that can be styled as needed.

npx shadcn@latest add https://jollyui.dev/default/datefield

Composed Components

A DateField uses the following components, which may also be used standalone or reused in other components.

Label

A label provides context for an element.

Reusable Wrapper - Example

If you will use a DateField in multiple places in your app, you can wrap all of the pieces into a reusable component. This way, the DOM structure, styling code, and other logic are defined in a single place and reused everywhere to ensure consistency.

The installed file includes a reusable wrapper JollyDateField. This wrapper serves as an excellent starting point for use throughout your codebase.

Event date
mm
dd
yyyy

The JollyDateField component extends the props of React Aria DateField and adds:

PropTypeDefaultDescription
labelstring | undefinedundefinedLabel for the date field
descriptionstring | undefinedundefinedDescription text for the date field
errorMessagestring | ((validation: AriaValidationResult) => string) | undefinedundefinedError message to display or function to generate it

You can copy this wrapper and create variations as needed for different use cases in your application. This approach promotes consistency while still allowing for flexibility in implementation.

Event date
mm
dd
yyyy

Examples

Basic

Birth date
mm
dd
yyyy

Values

Timezones

Event date
11
7
2022
12
45
AM
PST
Event date
11
7
2021
7
45
AM
UTC

Granularity

Date and Time
4
7
2021
6
45
22
PM
UTC
Date
4
7
2021

Validation

Appointment date
mm
dd
yyyy

Min/Max Values

Appointment date
mm
dd
yyyy

Description

Appointment date
mm
dd
yyyy
––
AM
Please select a weekday between 9 AM and 5 PM.