---
sidebar_position: 1
---
# Input Fields
Binding a DayPicker to an input field requires handling user interactions, synchronizing the selected date between the calendar and the field, and maintaining a good level of usability.
:::info Native Date Pickers
Browsers offer [native date pickers](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date) for easy date selection. However, their appearance and functionality vary across browsers and might not meet your customization needs. Use DayPicker for a tailored date picker that aligns with your app's design and accessibility standards.
:::
## Examples
### Input with Inline Calendar
See the [full source code](https://github.com/gpbl/react-day-picker/blob/main/examples/Input.tsx) and [unit tests](https://github.com/gpbl/react-day-picker/blob/main/examples/Input.test.tsx) for this example.
```tsx
import { useId, useState } from "react";
import { format, isValid, parse } from "date-fns";
import { DayPicker } from "react-day-picker";
/** Render an input field bound to a DayPicker calendar. */
export function Input() {
const inputId = useId();
// Hold the month in state to control the calendar when the input changes
const [month, setMonth] = useState(new Date());
// Hold the selected date in state
const [selectedDate, setSelectedDate] = useState(undefined);
// Hold the input value in state
const [inputValue, setInputValue] = useState("");
const handleDayPickerSelect = (date: Date | undefined) => {
if (!date) {
setInputValue("");
setSelectedDate(undefined);
} else {
setSelectedDate(date);
setMonth(date);
setInputValue(format(date, "MM/dd/yyyy"));
}
};
const handleInputChange = (e: React.ChangeEvent) => {
setInputValue(e.target.value); // Keep the input value in sync
const parsedDate = parse(e.target.value, "MM/dd/yyyy", new Date());
if (isValid(parsedDate)) {
setSelectedDate(parsedDate);
setMonth(parsedDate);
} else {
setSelectedDate(undefined);
}
};
return (
);
}
```
### Input with Date Picker Dialog
Implementing the date picker as a dialog requires careful consideration of accessibility. Refer to the [W3C ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/datepicker-dialog/) for guidance on creating an accessible date picker.
In this example, we use the native HTML `