Skip to content

Commit ea4f782

Browse files
authored
fix(date-picker): add check for calendar before setting (#18448)
* fix: add check for calendar before setting * fix: add another calendar check
1 parent 6a8f03b commit ea4f782

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

packages/web-components/src/components/date-picker/date-picker.ts

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -389,26 +389,27 @@ class CDSDatePicker extends HostListenerMixin(FormMixin(LitElement)) {
389389
value,
390390
} = this;
391391

392-
if (dateFormat) {
393-
this._setCalendar('dateFormat', calendar);
394-
}
392+
if (calendar) {
393+
if (dateFormat) {
394+
this._setCalendar('dateFormat', calendar);
395+
}
395396

396-
if (minDate || maxDate) {
397-
this._setCalendar('date', calendar);
398-
}
397+
if (minDate || maxDate) {
398+
this._setCalendar('date', calendar);
399+
}
399400

400-
if (open) {
401-
this._setCalendar('open', calendar);
402-
}
401+
if (open) {
402+
this._setCalendar('open', calendar);
403+
}
403404

404-
if (disabled || readonly) {
405-
this._setCalendar('disabled', calendar);
406-
}
407-
if (value) {
408-
this._setCalendar('value', calendar);
405+
if (disabled || readonly) {
406+
this._setCalendar('disabled', calendar);
407+
}
408+
if (value) {
409+
this._setCalendar('value', calendar);
410+
}
409411
}
410-
411-
return this.calendar;
412+
return calendar;
412413
}
413414

414415
/**
@@ -519,24 +520,29 @@ class CDSDatePicker extends HostListenerMixin(FormMixin(LitElement)) {
519520

520521
updated(changedProperties) {
521522
const { calendar } = this;
522-
if (calendar && changedProperties.has('dateFormat')) {
523-
this._setCalendar('dateFormat', calendar);
524-
}
525-
if (changedProperties.has('minDate') || changedProperties.has('maxDate')) {
526-
this._setCalendar('date', calendar);
527-
}
523+
if (calendar) {
524+
if (changedProperties.has('dateFormat')) {
525+
this._setCalendar('dateFormat', calendar);
526+
}
527+
if (
528+
changedProperties.has('minDate') ||
529+
changedProperties.has('maxDate')
530+
) {
531+
this._setCalendar('date', calendar);
532+
}
528533

529-
if (changedProperties.has('open') && calendar) {
530-
this._setCalendar('open', calendar);
531-
}
532-
if (
533-
changedProperties.has('disabled') ||
534-
changedProperties.has('readonly')
535-
) {
536-
this._setCalendar('disabled', calendar);
537-
}
538-
if (changedProperties.has('value')) {
539-
this._setCalendar('value', calendar);
534+
if (changedProperties.has('open')) {
535+
this._setCalendar('open', calendar);
536+
}
537+
if (
538+
changedProperties.has('disabled') ||
539+
changedProperties.has('readonly')
540+
) {
541+
this._setCalendar('disabled', calendar);
542+
}
543+
if (changedProperties.has('value')) {
544+
this._setCalendar('value', calendar);
545+
}
540546
}
541547
}
542548

0 commit comments

Comments
 (0)