Skip to content

Commit

Permalink
fix: add blur to datepicker upon valid selection
Browse files Browse the repository at this point in the history
  • Loading branch information
syam babu committed Dec 5, 2023
1 parent d3404d7 commit 946baa8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/DatePicker/DatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ import frLocale from 'antd/es/date-picker/locale/fr_CA';
import enLocale from 'antd/es/date-picker/locale/en_US';

function DatePickerStyled(props) {
const handleDateChange = (value) => {
if (value && value.isValid()) {
datePickerRef.current.blur();
}
if (props.onChange) {
props.onChange(value);
}
};

const datePickerRef = React.createRef();

return (
<DatePicker
ref={datePickerRef}
format="DD/MM/YYYY"
size="large"
locale={i18n?.language === 'en' ? enLocale : i18n?.language === 'fr' && frLocale}
className="date-picker-wrapper"
{...props}
changeOnBlur={true}
placeholder={i18n?.language === 'en' ? 'DD/MM/YYYY' : 'JJ/MM/AAAA'}
showToday={false}
popupClassName="date-picker-calendar"
getPopupContainer={(trigger) => trigger.parentNode}
onChange={handleDateChange}
/>
);
}
Expand Down

0 comments on commit 946baa8

Please sign in to comment.