DateInput
Captures a date with the platform's native picker. Values are ISO date strings.
- Overview
- Props
DateInput captures a date with the platform's native picker. value, defaultValue, min, max and onChange all use ISO date strings (YYYY-MM-DD).
It accepts the other TextInput props, except type and placeholder.
Usage
Enter your date of birth
Controlled
You can control the DateInput by providing value and onChange props. The value should be in ISO date format (YYYY-MM-DD):
import { useState } from "react";
import { DateInput } from "murray";
function Demo() {
const [value, setValue] = useState("2024-01-15");
return <DateInput value={value} onChange={(newValue) => setValue(newValue)} />;
}
Error state
Like other form inputs, DateInput supports error states with boolean or string error messages:
Please enter a valid date
Disabled state
Required field
Use the required prop to mark the field as required, which adds a red asterisk to the label:
This field is required
Date range
Use min and max to limit the selectable dates:
<DateInput label="Start date" min="2024-01-01" max="2024-12-31" />
Inline picker (iOS)
On iOS, inline shows the spinner in place of the input. Other platforms ignore it.
<DateInput label="Start date" inline />
Prefix and suffix
You can use prefix and suffix props to add icons or other elements to the left and right side of the input:
UTC
Condensed theme
For applications with condensed theme density, this component renders in a condensed style:
Usage in <Form>
On web, DateInput can be used in <Form> component and be controlled by Formik. This example shows date validation including age verification:
Date Format
The DateInput component:
- Input: Accepts ISO date strings (YYYY-MM-DD format)
- Output: Always outputs ISO date strings or
undefined - Display: Web uses the browser format, mobile shows DD/MM/YYYY
Platform Behavior
- Web: Renders as
<input type="date">with native browser date picker - iOS: Pressing the input opens a bottom sheet with a spinner and a confirm button, or the spinner shows in place with
inline - Android: Pressing the input opens the native date picker dialog
Accessibility
The DateInput component is fully accessible and includes:
- Proper ARIA labels and descriptions
- Keyboard navigation support
- Screen reader compatibility
- Native date picker accessibility features
Migration from DateInputDeprecated
If you're migrating from DateInputDeprecated:
// Before (DateInputDeprecated)
<DateInputDeprecated
label="Date"
locale="en"
onChange={(value) => setValue(value)}
/>
// After (DateInput)
<DateInput
label="Date"
onChange={(value) => setValue(value)}
/>
Key differences:
- No
localeprop needed (uses native browser/OS locale) - No custom date formatting (uses ISO strings)
- Simplified API with better platform integration
Playground
murray and murray/mobile.DateInput props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-describedby | stringundefined | Id of an element outside the input that also describes it, such as an error shared by several inputs | ||
| aria-label | stringundefined | Accessibility label, only necessary when not associated with a label | ||
| aria-labelledby | stringundefined | |||
| aria-required | booleanundefined | Overrides `aria-required` set by `required`, to mark the input as mandatory without the asterisk | ||
| autoFocus | booleanundefined | If true, focuses the input on componentDidMount.The default value is false. | ||
| cursor | Cursorundefined | Enforce a cursor type | ||
| defaultValue | stringundefined | yyyy-MM-dd | ||
| disabled | booleanundefined | Disable input | ||
| enterKeyHint | 6 possibilities"search""done""go""next""send"undefined | |||
| error | ReactNode | Contents of `InputError` component, if not set, error is not rendered. | ||
| focused | booleanundefined | Show focus styles even when the input isn't focused, e.g. while a readonly input's picker is open | ||
| groupLabel | ReactNode | Name of the group the input belongs to, such as the date its day field is part of. VoiceOver and TalkBack don't announce it when focus lands on the input, so on native it ends the input's accessible name, after `label`. Ignored without a `label`. | ||
| helpText | ReactNode | Contents of `InputHelp` component, if not set, description is not rendered. | ||
| id | stringundefined | |||
| inline | booleanundefined | Renders the picker in place instead of opening it from the input @platform ios | ||
| label | ReactNode | |||
| max | stringundefined | Latest selectable date, yyyy-MM-dd | ||
| maxLength | numberundefined | Maximum string length that the user can enter in UTF-16 code units | ||
| min | stringundefined | Earliest selectable date, yyyy-MM-dd | ||
| minLength | numberundefined | Maximum string length that the user can enter in UTF-16 code units @platform web | ||
| name | stringundefined | Html input name @platform web | ||
| onChange | ((value: string) => void)undefined | Trigger when input value is changing | ||
| onPress | 2 possibilities((event: GestureResponderEvent) => void)undefined | |||
| prefix | ReactNode | Content section rendered on the left side of the input | ||
| prefixPointerEvents | 5 possibilities"none""auto""box-none""box-only"undefined | Sets pointer-events styles on the `prefix` element, `none` by default | ||
| readonly | booleanundefined | Make input readonly | ||
| render | 2 possibilities((elements: { input: ReactNode; prefix?: ReactNode; suffix?: ReactNode; }, pseudoState: PseudoState) => ReactNode)undefined | Fully control how input, prefix and suffix are rendererd | ||
| renderPlaceholder | (() => ReactNode)undefined | To render a custom placeholder view when the field is empty | ||
| required | booleanundefined | Adds required attribute to the input and a red asterisk on the right side of label, `false` by default Determines whether the input should have `aria-required` attribute | ||
| step | stringnumberundefined | @platform web | ||
| suffix | ReactNode | Content section rendered on the right side of the input | ||
| suffixPointerEvents | 5 possibilities"none""auto""box-none""box-only"undefined | Sets pointer-events styles on the `suffix` element, `none` by default | ||
| sx | PositionPropsundefined | Positioning properties | ||
| title | stringundefined | Html input title @platform web | ||
| value | stringundefined | yyyy-MM-dd |
Undocumented props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| autoComplete | any | |||
| onBlur | any | |||
| onSubmitEditing | any | |||
| ref | any | |||
| testID | any |
Style API
Use sx for one-off adjustments. It accepts these style keys:
Each can be overridden per breakpoint with: