# DateRangeField (@limerdev/zest) A period typed as two dates, segment by segment: `` (`bind:value` a `{ start, end }` of `DateValue`s, `granularity`, `minValue`, `maxValue`) holds a `DateRangeField.Label` (which names both dates; use it instead of `Field.Label`) and `DateRangeField.Inputs`, one box that draws the start and end `DateRangeField.Input`s (`type="start"`, `"end"`). Inside a `Field`, its description and error describe the inputs. - Category: Data input - Import: `import { DateRangeField } from '@limerdev/zest'` - Bits UI: `DateRangeField`, https://bits-ui.com/docs/components/date-range-field - Exports: `DateRangeField.Root`, `DateRangeField.Label`, `DateRangeField.Inputs`, `DateRangeField.Input`, `DateRangeField.Segment` - Use for: A period people type: a contract's term, a report's dates, an absence. - Don't: Picking a period where seeing the months helps: use `DateRangePicker`. One date: use `DateField`. ```svelte Contract term ``` Props of `DateRangeField.Root`: - `disabled` (`boolean`, default `false`): If true, the date field will be disabled and users will not be able to interact with it. This also disables the hidden input element if the date field is used in a form. - `errorMessageId` (`string`): The `id` of the element which contains the error messages for the date field when the date is invalid. - `granularity` (`"day" | "hour" | "minute" | "second"`, default `'day'`): The granularity of the date field. This determines which segments will be includes in the segments array used to build the date field. By default, when a `CalendarDate` value is used, the granularity will default to `'day'`, and when a `CalendarDateTime` or `ZonedDateTime` value is used, the granularity will default to `'minute'`. Granularity is only used for visual purposes, and does not impact the value of the date field. You can have the same value synced between multiple date fields with different granularities and they will all contain the same value. - `hideTimeZone` (`boolean`, default `false;`): Whether or not to hide the timeZoneName segment from the date field. - `hourCycle` (`12 | 24`, default `the locale's default time format`): The format to use for displaying the time in the input. If using a 12 hour clock, ensure you also include the `dayPeriod` segment in your input to ensure the user can select AM/PM. - `locale` (`string`, default `'en'`): The locale to use for formatting the date field. - `maxValue` (`DateValue`): The maximum acceptable date. When provided, the date field will be marked as invalid if the user enters a date after this date. - `minValue` (`DateValue`): The minimum acceptable date. When provided, the date field will be marked as invalid if the user enters a date before this date. - `onEndValueChange` (`OnChangeFn`): A callback function called when the end value changes. This doesn't necessarily mean the `value` has updated and should be used to apply cosmetic changes to the calendar when only part of the value is changed/completed. - `onInvalid` (`DateOnInvalid`): A callback fired when the date field's value is invalid. Use this to display an error message to the user. - `onPlaceholderChange` (`OnChangeFn`): A callback that is called when the date field's placeholder value changes. - `onStartValueChange` (`OnChangeFn`): A callback function called when the start value changes. This doesn't necessarily mean the `value` has updated and should be used to apply cosmetic changes to the calendar when only part of the value is changed/completed. - `onValueChange` (`OnChangeFn`): A callback that is called when the value of the date range field changes. - `placeholder` (`DateValue`, bindable): The placeholder value of the date field. This determines the format and what date the field starts at when it is empty. - `readonly` (`boolean`, default `false`): If true, the date field will be readonly, and users will not be able to edit the values of any of the individual segments. - `readonlySegments` (`("month" | "year" | "day" | "hour" | "minute" | "second" | "dayPeriod")[]`): An array of segment names that should be readonly. If provided, only the segments not in this array will be editable. - `required` (`boolean`, default `false`): If true, the date field will be required, which is useful when used within a form. If the date field is empty when the form is submitted, the form will not be valid. - `validate` (`DateRangeValidator`): A function that returns a string or array of strings as validation errors if the date is invalid, or nothing if the date is valid - `value` (`DateRange`, bindable): The value of the date range field. Props of `DateRangeField.Input`: - `name` (`string`): The name to use for the hidden input element associated with this input used for form submission. - `type` (`"start" | "end"`, required): Whether this input represents the start or end of the date range. Props of `DateRangeField.Segment`: - `part` (`"month" | "year" | "day" | "hour" | "minute" | "second" | "dayPeriod" | "timeZoneName" | "literal"`, required) Example: Basic One box with the start and end dates. ```svelte Contract term {term.start?.toString() ?? '…'} to {term.end?.toString() ?? '…'} ```