Skip to content

Commit

Permalink
fix: allow optional onChange
Browse files Browse the repository at this point in the history
  • Loading branch information
remadex committed Dec 6, 2024
1 parent 45c6fe4 commit fd94016
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/ember-input/src/components/tpk-datepicker-input.gts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface TpkDatepickerInputArgs {
disabledHours?: number[];
enabledHours?: number[];
viewMode?: 'clock' | 'calendar' | 'months' | 'years' | 'decades';
onChange: (value: Date[]) => void;
onChange?: (value: Date[]) => void;
onClose?: () => void;
}

Expand Down Expand Up @@ -174,14 +174,16 @@ export default class TpkDatepickerNewInputComponent extends Component<TpkDatepic

if (this.args.onChange) {
this.datepicker.subscribe(Namespace.events.change, () => {
if (this.args.mode === 'multiple' || this.args.mode === 'range') {
// Workaround to trigger change event after at least 2 dates are picked
if (this.datepicker!.dates.picked.length > 1) {
return this.args.onChange(this.datepicker!.dates.picked);
if (this.args.onChange) {
if (this.args.mode === 'multiple' || this.args.mode === 'range') {
// Workaround to trigger change event after at least 2 dates are picked
if (this.datepicker!.dates.picked.length > 1) {
return this.args.onChange(this.datepicker!.dates.picked);
}
return;
}
return;
this.args.onChange(this.datepicker!.dates.picked);
}
this.args.onChange(this.datepicker!.dates.picked);
});
}
if (this.args.onClose) {
Expand Down

0 comments on commit fd94016

Please sign in to comment.