A composite date picker built from Input and Calendar. The calendar opens when the input receives focus and closes when focus is lost, with interaction detection to keep the calendar open during use.
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
props | object | Component props. Properties
| ||||||||||||||||||||||||
ref | object | | Forwarded ref. |
- Since
- 5.7.0
DatePicker component.
- Type:
- JSX.
Element
import { useState } from 'react';
import DatePicker from '@gravityforms/components/react/admin/modules/DatePicker';
export default function CampaignDateField() {
const [ date, setDate ] = useState( null );
const [ formatted, setFormatted ] = useState( '' );
return (
<DatePicker
dateFormat="yyyy-MM-dd"
inputAttributes={{
labelAttributes: { label: 'Launch Date' },
helpTextAttributes: { content: 'Use the YYYY-MM-DD format.' },
}}
onChange={ ( value, meta ) => {
setDate( value );
setFormatted( meta.formattedValue );
} }
calendarAttributes={{
calendarAttributes: { selectRange: false },
}}
/>
);
}