Date Field
NewA field for typing a date, one segment at a time.
Preview
Installation
npx sigma-ui@latest add date-fieldUsage
<script setup lang="ts">
import { ref } from 'vue';
import { type DateValue } from '@internationalized/date';
import { DateField } from '@/components/ui/date-field';
const value = ref<DateValue>();
</script>
<template>
<DateField v-model="value" />
</template>v-modelis an @internationalized/dateDateValue.CalendarDategives day segments, andCalendarDateTimeorZonedDateTimeadd time segments.granularitypicks the smallest segment (dayby default, orhour,minute,second), andhourCycleswitches between a 12-hour and a 24-hour clock.minValueandmaxValuelimit the range. A value outside it setsdata-invalidon the field, and the field shows the destructive border.- The field renders each segment in a
DateFieldInput. Pass your own default slot to render the segments yourself, for example to add an icon. - Give the field an
idand point a label at it withfor. Clicking the label focuses the first segment.
Related
- Time Field
- Date Picker, when the date is picked from a calendar
Examples
With label
Granularity and hour cycle
Min and max
Disabled
Invalid
Form
API Reference
DateField
Props
| Prop | Type | Default |
|---|---|---|
defaultValueThe default value for the calendar | DateValue | - |
defaultPlaceholderThe default placeholder date | DateValue | - |
placeholderThe placeholder date, which is used to determine what month to display when no date is selected. This updates as the user navigates the calendar and can be used to programmatically control the calendar view | DateValue | - |
modelValueThe controlled value of the field. Can be bound as | DateValue | null | - |
hourCycleThe hour cycle used for formatting times. Defaults to the local preference | HourCycle | - |
stepThe stepping interval for the time fields. Defaults to | DateStep | - |
stepSnappingWhether to enforce snapping the time value to the nearest step increment after input. Defaults to | boolean | - |
granularityThe granularity to use for formatting times. Defaults to day if a CalendarDate is provided, otherwise defaults to minute. The field will render segments for each part of the date up to and including the specified granularity | Granularity | - |
hideTimeZoneWhether or not to hide the time zone segment of the field | boolean | - |
maxValueThe maximum date that can be selected | DateValue | - |
minValueThe minimum date that can be selected | DateValue | - |
localeThe locale to use for formatting dates | string | - |
disabledWhether or not the date field is disabled | boolean | - |
readonlyWhether or not the date field is readonly | boolean | - |
isDateUnavailableA function that returns whether or not a date is unavailable | Matcher | - |
idId of the element | string | - |
dirThe reading direction of the date field when applicable. <br> If omitted, inherits globally from | Direction | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called whenever the model value changes | [date: DateValue] |
update:placeholderEvent handler called whenever the placeholder value changes | [date: DateValue] |
Slots
| Slot | Scope |
|---|---|
defaultThe date segments. Each one renders in a | { modelValue: DateValue | null; segments: { part: SegmentPart; value: string; }[]; isInvalid: boolean; } |
DateFieldInput
Props
| Prop | Type | Default |
|---|---|---|
partrequiredThe part of the date to render | SegmentPart | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
The field is a group of spin buttons, one for each segment (month, day, and year). Typing a number fills the focused segment and moves to the next one.
| Key | Description |
|---|---|
| ArrowUp or ArrowDown | Increases or decreases the focused segment. |
| ArrowLeft or ArrowRight | Moves to the previous or next segment. |
| Backspace | Deletes the last digit of the focused segment. |
| Tab | Moves to the next segment, then out of the field. |