Skip to content

Commit

Permalink
feat(DatePicker): adds closeOnSelect
Browse files Browse the repository at this point in the history
Closes #268
  • Loading branch information
aditya-kumawat committed Sep 7, 2020
1 parent 298a22d commit c0ea446
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/components/organisms/datePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ type CompProps = {
* `(format: string, val: string) => boolean`
*/
validator?: Validator;
/**
* Close Popover on date selection
*/
closeOnSelect?: boolean;
} & SharedProps;

const defaultProps = {
position: 'bottom-start',
inputFormat: 'mm/dd/yyyy',
outputFormat: 'mm/dd/yyyy',
validator: validators.date,
inputOptions: {}
inputOptions: {},
closeOnSelect: true
};

type DefaultProps = Readonly<typeof defaultProps>;
Expand Down Expand Up @@ -165,6 +170,12 @@ export class DatePicker extends React.Component<DatePickerProps, DatePickerState

onDateChangeHandler = (d?: Date) => {
this.setState({ date: d });

const {
closeOnSelect
} = this.props;

if (closeOnSelect) this.setState({ open: false });
}

onChangeHandler = (_e: React.ChangeEvent<HTMLInputElement>, val?: string) => {
Expand Down Expand Up @@ -222,6 +233,7 @@ export class DatePicker extends React.Component<DatePickerProps, DatePickerState
disabledBefore,
disabledAfter,
onDateChange,
closeOnSelect,
...rest
} = this.props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const all = () => {
false
);

const closeOnSelect = boolean(
'closeOnSelect',
true
);

const inputFormat = select(
'inputFormat',
['mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy-mm-dd', 'mm-dd-yyyy', 'dd-mm-yyyy', 'yyyy-mm-dd'],
Expand Down Expand Up @@ -79,6 +84,7 @@ export const all = () => {
return (
<DatePicker
withInput={withInput}
closeOnSelect={closeOnSelect}
open={open}
inputFormat={inputFormat}
outputFormat={outputFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export const withInput = () => {
-1
);

const closeOnSelect = boolean(
'closeOnSelect',
true
);

const attr: Record<string, any> = {};
if (disabledBefore) attr.disabledBefore = disabledBefore;
if (disabledAfter) attr.disabledAfter = disabledAfter;
Expand All @@ -69,6 +74,7 @@ export const withInput = () => {
<div className="w-25">
<DatePicker
withInput={true}
closeOnSelect={closeOnSelect}
inputFormat={inputFormat}
outputFormat={outputFormat}
jumpView={jumpView}
Expand Down

0 comments on commit c0ea446

Please sign in to comment.