-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdate-picker.ts
More file actions
818 lines (714 loc) · 25.9 KB
/
date-picker.ts
File metadata and controls
818 lines (714 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
import { LitElement, type TemplateResult, html, nothing } from 'lit';
import { property, query, queryAssignedElements } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { getThemeController, themes } from '../../theming/theming-decorator.js';
import IgcCalendarComponent, { focusActiveDate } from '../calendar/calendar.js';
import { convertToDate } from '../calendar/helpers.js';
import {
type CalendarHeaderOrientation,
type DateRangeDescriptor,
DateRangeType,
type WeekDays,
} from '../calendar/types.js';
import {
addKeybindings,
altKey,
arrowDown,
arrowUp,
escapeKey,
} from '../common/controllers/key-bindings.js';
import { blazorAdditionalDependencies } from '../common/decorators/blazorAdditionalDependencies.js';
import { watch } from '../common/decorators/watch.js';
import { registerComponent } from '../common/definitions/register.js';
import {
IgcCalendarResourceStringEN,
type IgcCalendarResourceStrings,
} from '../common/i18n/calendar.resources.js';
import { IgcBaseComboBoxLikeComponent } from '../common/mixins/combo-box.js';
import type { AbstractConstructor } from '../common/mixins/constructor.js';
import { EventEmitterMixin } from '../common/mixins/event-emitter.js';
import { FormAssociatedRequiredMixin } from '../common/mixins/forms/associated-required.js';
import {
type FormValue,
createFormValueState,
defaultDateTimeTransformers,
} from '../common/mixins/forms/form-value.js';
import { createCounter, findElementFromEventPath } from '../common/util.js';
import IgcDateTimeInputComponent from '../date-time-input/date-time-input.js';
import type { DatePart } from '../date-time-input/date-util.js';
import IgcDialogComponent from '../dialog/dialog.js';
import IgcFocusTrapComponent from '../focus-trap/focus-trap.js';
import IgcIconComponent from '../icon/icon.js';
import IgcPopoverComponent from '../popover/popover.js';
import type {
ContentOrientation,
PickerMode,
RangeTextSelectMode,
SelectionRangeDirection,
} from '../types.js';
import IgcValidationContainerComponent from '../validation-container/validation-container.js';
import { styles } from './themes/date-picker.base.css.js';
import { styles as shared } from './themes/shared/date-picker.common.css.js';
import { all } from './themes/themes.js';
import { datePickerValidators } from './validators.js';
export interface IgcDatePickerComponentEventMap {
igcOpening: CustomEvent<void>;
igcOpened: CustomEvent<void>;
igcClosing: CustomEvent<void>;
igcClosed: CustomEvent<void>;
igcChange: CustomEvent<Date>;
igcInput: CustomEvent<Date>;
}
const formats = new Set(['short', 'medium', 'long', 'full']);
/**
* igc-date-picker is a feature rich component used for entering a date through manual text input or
* choosing date values from a calendar dialog that pops up.
*
* @element igc-date-picker
*
* @slot prefix - Renders content before the input.
* @slot suffix - Renders content after the input.
* @slot helper-text - Renders content below the input.
* @slot bad-input - Renders content when the value is in the disabledDates ranges.
* @slot value-missing - Renders content when the required validation fails.
* @slot range-overflow - Renders content when the max validation fails.
* @slot range-underflow - Renders content when the min validation fails.
* @slot custom-error - Renders content when setCustomValidity(message) is set.
* @slot invalid - Renders content when the component is in invalid state (validity.valid = false).
* @slot title - Renders content in the calendar title.
* @slot header-date - Renders content instead of the current date/range in the calendar header.
* @slot clear-icon - Renders a clear icon template.
* @slot calendar-icon - Renders the icon/content for the calendar picker.
* @slot calendar-icon-open - Renders the icon/content for the picker in open state.
* @slot actions - Renders content in the action part of the picker in open state.
*
* @fires igcOpening - Emitted just before the calendar dropdown is shown.
* @fires igcOpened - Emitted after the calendar dropdown is shown.
* @fires igcClosing - Emitted just before the calendar dropdown is hidden.
* @fires igcClosed - Emitted after the calendar dropdown is hidden.
* @fires igcChange - Emitted when the user modifies and commits the elements's value.
* @fires igcInput - Emitted when when the user types in the element.
*
* @csspart label - The label wrapper that renders content above the target input.
* @csspart container - The main wrapper that holds all main input elements.
* @csspart input - The native input element.
* @csspart prefix - The prefix wrapper.
* @csspart suffix - The suffix wrapper.
* @csspart calendar-icon - The calendar icon wrapper for closed state.
* @csspart calendar-icon-open - The calendar icon wrapper for opened state.
* @csspart clear-icon - The clear icon wrapper.
* @csspart actions - The actions wrapper.
* @csspart helper-text - The helper-text wrapper that renders content below the target input.
* @csspart header - The calendar header element.
* @csspart header-title - The calendar header title element.
* @csspart header-date - The calendar header date element.
* @csspart calendar-content - The calendar content element which contains the views and navigation elements.
* @csspart navigation - The calendar navigation container element.
* @csspart months-navigation - The calendar months navigation button element.
* @csspart years-navigation - The calendar years navigation button element.
* @csspart years-range - The calendar years range element.
* @csspart navigation-buttons - The calendar navigation buttons container.
* @csspart navigation-button - The calendar previous/next navigation button.
* @csspart days-view-container - The calendar days view container element.
* @csspart days-view - The calendar days view element.
* @csspart months-view - The calendar months view element.
* @csspart years-view - The calendar years view element.
* @csspart days-row - The calendar days row element.
* @csspart calendar-label - The calendar week header label element.
* @csspart week-number - The calendar week number element.
* @csspart week-number-inner - The calendar week number inner element.
* @csspart date - The calendar date element.
* @csspart date-inner - The calendar date inner element.
* @csspart first - The calendar first selected date element in range selection.
* @csspart last - The calendar last selected date element in range selection.
* @csspart inactive - The calendar inactive date element.
* @csspart hidden - The calendar hidden date element.
* @csspart weekend - The calendar weekend date element.
* @csspart range - The calendar range selected element.
* @csspart special - The calendar special date element.
* @csspart disabled - The calendar disabled date element.
* @csspart single - The calendar single selected date element.
* @csspart preview - The calendar range selection preview date element.
* @csspart month - The calendar month element.
* @csspart month-inner - The calendar month inner element.
* @csspart year - The calendar year element.
* @csspart year-inner - The calendar year inner element.
* @csspart selected - The calendar selected state for element(s). Applies to date, month and year elements.
* @csspart current - The calendar current state for element(s). Applies to date, month and year elements.
*/
@themes(all, { exposeController: true })
@blazorAdditionalDependencies(
'IgcCalendarComponent, IgcDateTimeInputComponent, IgcDialogComponent, IgcIconComponent'
)
export default class IgcDatePickerComponent extends FormAssociatedRequiredMixin(
EventEmitterMixin<
IgcDatePickerComponentEventMap,
AbstractConstructor<IgcBaseComboBoxLikeComponent>
>(IgcBaseComboBoxLikeComponent)
) {
public static readonly tagName = 'igc-date-picker';
public static styles = [styles, shared];
protected static shadowRootOptions = {
...LitElement.shadowRootOptions,
delegatesFocus: true,
};
private static readonly increment = createCounter();
protected inputId = `date-picker-${IgcDatePickerComponent.increment()}`;
protected override get __validators() {
return datePickerValidators;
}
/* blazorSuppress */
public static register() {
registerComponent(
IgcDatePickerComponent,
IgcCalendarComponent,
IgcDateTimeInputComponent,
IgcFocusTrapComponent,
IgcIconComponent,
IgcPopoverComponent,
IgcDialogComponent,
IgcValidationContainerComponent
);
}
private _activeDate: Date | null = null;
private _min: Date | null = null;
private _max: Date | null = null;
private _disabledDates?: DateRangeDescriptor[];
private _dateConstraints?: DateRangeDescriptor[];
private _displayFormat?: string;
private _inputFormat?: string;
private get isDropDown() {
return this.mode === 'dropdown';
}
@query(IgcDateTimeInputComponent.tagName)
private _input!: IgcDateTimeInputComponent;
@query(IgcCalendarComponent.tagName)
private _calendar!: IgcCalendarComponent;
@queryAssignedElements({ slot: 'prefix' })
private prefixes!: Array<HTMLElement>;
@queryAssignedElements({ slot: 'suffix' })
private suffixes!: Array<HTMLElement>;
@queryAssignedElements({ slot: 'actions' })
private actions!: Array<HTMLElement>;
@queryAssignedElements({ slot: 'header-date' })
private headerDateSlotItems!: Array<HTMLElement>;
protected get _isMaterialTheme(): boolean {
return getThemeController(this)?.theme === 'material';
}
protected override _formValue: FormValue<Date | null>;
/**
* Sets the state of the datepicker dropdown.
* @attr
*/
@property({ type: Boolean, reflect: true })
public override open = false;
/**
* The label of the datepicker.
* @attr label
*/
@property()
public label!: string;
/**
* Determines whether the calendar is opened in a dropdown or a modal dialog
* @attr mode
*/
@property()
public mode: PickerMode = 'dropdown';
/**
* Whether to allow typing in the input.
* @attr non-editable
*/
@property({ type: Boolean, reflect: true, attribute: 'non-editable' })
public nonEditable = false;
/**
* Makes the control a readonly field.
* @attr readonly
*/
@property({ type: Boolean, reflect: true, attribute: 'readonly' })
public readOnly = false;
/* @tsTwoWayProperty(true, "igcChange", "detail", false) */
/**
* The value of the picker
* @attr
*/
@property({ converter: convertToDate })
public set value(value: Date | string | null | undefined) {
this._formValue.setValueAndFormState(value as Date | null);
this._validate();
}
public get value(): Date | null {
return this._formValue.value;
}
/**
* Gets/Sets the date which is shown in the calendar picker and is highlighted.
* By default it is the current date.
*/
@property({ attribute: 'active-date', converter: convertToDate })
public set activeDate(value: Date | string | null | undefined) {
this._activeDate = convertToDate(value);
}
public get activeDate(): Date {
return this._activeDate ?? this._calendar?.activeDate;
}
/**
* The minimum value required for the date picker to remain valid.
* @attr
*/
@property({ converter: convertToDate })
public set min(value: Date | string | null | undefined) {
this._min = convertToDate(value);
this.setDateConstraints();
this._updateValidity();
}
public get min(): Date | null {
return this._min;
}
/**
* The maximum value required for the date picker to remain valid.
* @attr
*/
@property({ converter: convertToDate })
public set max(value: Date | string | null | undefined) {
this._max = convertToDate(value);
this.setDateConstraints();
this._updateValidity();
}
public get max(): Date | null {
return this._max;
}
/**
* The orientation of the calendar header.
* @attr header-orientation
*/
@property({ attribute: 'header-orientation', reflect: true })
public headerOrientation: CalendarHeaderOrientation = 'horizontal';
/**
* The orientation of the multiple months displayed in the calendar's days view.
* @attr
*/
@property()
public orientation: ContentOrientation = 'horizontal';
/**
* Determines whether the calendar hides its header.
* @attr hide-header
*/
@property({ type: Boolean, reflect: true, attribute: 'hide-header' })
public hideHeader = false;
/**
* Controls the visibility of the dates that do not belong to the current month.
* @attr hide-outside-days
*/
@property({ type: Boolean, reflect: true, attribute: 'hide-outside-days' })
public hideOutsideDays = false;
/** Gets/sets disabled dates. */
@property({ attribute: false })
public set disabledDates(dates: DateRangeDescriptor[]) {
this._disabledDates = dates;
this.setDateConstraints();
this._updateValidity();
}
public get disabledDates() {
return this._disabledDates as DateRangeDescriptor[];
}
/** Gets/sets special dates. */
@property({ attribute: false })
public specialDates!: DateRangeDescriptor[];
/**
* Whether the control will have outlined appearance.
* @attr
*/
@property({ reflect: true, type: Boolean })
public outlined = false;
/**
* The placeholder attribute of the control.
* @attr
*/
@property()
public placeholder!: string;
/**
* The number of months displayed in the calendar.
* @attr visible-months
*/
@property({ type: Number, attribute: 'visible-months' })
public visibleMonths = 1;
/**
* Whether to show the number of the week in the calendar.
* @attr show-week-numbers
*/
@property({ type: Boolean, reflect: true, attribute: 'show-week-numbers' })
public showWeekNumbers = false;
/**
* Format to display the value in when not editing.
* Defaults to the input format if not set.
* @attr display-format
*/
@property({ attribute: 'display-format' })
public set displayFormat(value: string) {
this._displayFormat = value;
}
public get displayFormat(): string {
return this._displayFormat ?? this.inputFormat;
}
/**
* The date format to apply on the input.
* Defaults to the current locale Intl.DateTimeFormat
* @attr input-format
*/
@property({ attribute: 'input-format' })
public set inputFormat(value: string) {
this._inputFormat = value;
}
public get inputFormat(): string {
return this._inputFormat ?? this._input?.inputFormat;
}
/**
* The locale settings used to display the value.
* @attr
*/
@property()
public locale = 'en';
/** The prompt symbol to use for unfilled parts of the mask.
* @attr
*/
@property()
public prompt = '_';
/** The resource strings of the calendar. */
@property({ attribute: false })
public resourceStrings: IgcCalendarResourceStrings =
IgcCalendarResourceStringEN;
@watch('open')
protected openChange() {
this._rootClickController.update();
}
/** Sets the start day of the week for the calendar. */
@property({ attribute: 'week-start' })
public weekStart: WeekDays = 'sunday';
constructor() {
super();
this._formValue = createFormValueState<Date | null>(this, {
initialValue: null,
transformers: defaultDateTimeTransformers,
});
this.addEventListener('focusin', this.handleFocusIn);
this.addEventListener('focusout', this.handleFocusOut);
this._rootClickController.update({ hideCallback: this.handleClosing });
addKeybindings(this, {
skip: () => this.disabled,
bindingDefaults: { preventDefault: true },
})
.set([altKey, arrowDown], this.handleAnchorClick)
.set([altKey, arrowUp], this.onEscapeKey)
.set(escapeKey, this.onEscapeKey);
}
protected override createRenderRoot() {
const root = super.createRenderRoot();
root.addEventListener('slotchange', () => this.requestUpdate());
return root;
}
/** Clears the input part of the component of any user input */
public clear() {
this.value = null;
this._input?.clear();
}
/** Increments the passed in date part */
public stepUp(datePart?: DatePart, delta?: number): void {
this._input.stepUp(datePart, delta);
}
/** Decrements the passed in date part */
public stepDown(datePart?: DatePart, delta?: number): void {
this._input.stepDown(datePart, delta);
}
/** Selects the text in the input of the component */
public select(): void {
this._input.select();
}
/** Sets the text selection range in the input of the component */
public setSelectionRange(
start: number,
end: number,
direction?: SelectionRangeDirection
): void {
this._input.setSelectionRange(start, end, direction);
}
/* Replaces the selected text in the input and re-applies the mask */
public setRangeText(
replacement: string,
start: number,
end: number,
mode?: RangeTextSelectMode
): void {
this._input.setRangeText(replacement, start, end, mode);
this.value = this._input.value;
}
protected async onEscapeKey() {
if (await this._hide(true)) {
this._input.focus();
}
}
protected handleFocusIn() {
this._dirty = true;
}
protected handleFocusOut({ relatedTarget }: FocusEvent) {
if (!this.contains(relatedTarget as Node)) {
this.checkValidity();
}
}
protected handlerCalendarIconSlotPointerDown(event: PointerEvent) {
// This is where the delegateFocus of the underlying input is a chore.
// If we have a required validator we don't want the input to enter an invalid
// state right off the bat when opening the picker which will happen since focus is transferred to the calendar element.
// So we call preventDefault on the event in order to not focus the input and trigger its validation logic on blur.
event.preventDefault();
}
protected handleInputClick(event: Event) {
if (findElementFromEventPath('input', event)) {
// Open only if the click originates from the underlying input
this.handleAnchorClick();
}
}
protected override async handleAnchorClick() {
this._calendar.activeDate = this.value ?? this._calendar.activeDate;
super.handleAnchorClick();
await this.updateComplete;
this._calendar[focusActiveDate]();
}
private async _shouldCloseCalendarDropdown() {
if (!this.keepOpenOnSelect && (await this._hide(true))) {
this._input.focus();
this._input.select();
}
}
protected handleInputChangeEvent(event: CustomEvent<Date>) {
event.stopPropagation();
this.value = (event.target as IgcDateTimeInputComponent).value!;
this.emitEvent('igcChange', { detail: this.value });
}
protected async handleCalendarChangeEvent(event: CustomEvent<Date>) {
event.stopPropagation();
if (this.readOnly) {
// Wait till the calendar finishes updating and then restore the current value from the date-picker.
await this._calendar.updateComplete;
this._calendar.value = this.value;
return;
}
this.value = (event.target as IgcCalendarComponent).value!;
this.emitEvent('igcChange', { detail: this.value });
this._shouldCloseCalendarDropdown();
}
protected handleInputEvent(event: CustomEvent<Date>) {
event.stopPropagation();
if (this.nonEditable) {
event.preventDefault();
return;
}
this.value = (event.target as IgcDateTimeInputComponent).value!;
this.emitEvent('igcInput', { detail: this.value });
}
protected handleClosing() {
this._hide(true);
}
protected handleDialogClosing(event: Event) {
event.stopPropagation();
this._hide(true);
}
protected handleDialogClosed(event: Event) {
event.stopPropagation();
}
private setDateConstraints() {
const dates: DateRangeDescriptor[] = [];
if (this._min) {
dates.push({
type: DateRangeType.Before,
dateRange: [this._min],
});
}
if (this._max) {
dates.push({
type: DateRangeType.After,
dateRange: [this._max],
});
}
if (this._disabledDates?.length) {
dates.push(...this.disabledDates);
}
this._dateConstraints = dates.length ? dates : undefined;
}
private renderClearIcon() {
return !this.value
? nothing
: html`
<span slot="suffix" part="clear-icon" @click=${this.clear}>
<slot name="clear-icon">
<igc-icon
name="input_clear"
collection="default"
aria-hidden="true"
></igc-icon>
</slot>
</span>
`;
}
private renderCalendarIcon() {
const defaultIcon = html`
<igc-icon name="today" collection="default" aria-hidden="true"></igc-icon>
`;
const state = this.open ? 'calendar-icon-open' : 'calendar-icon';
return html`
<span
slot="prefix"
part=${state}
@pointerdown=${this.handlerCalendarIconSlotPointerDown}
@click=${this.handleAnchorClick}
>
<slot name=${state}>${defaultIcon}</slot>
</span>
`;
}
private renderCalendarSlots() {
if (this.isDropDown) {
return nothing;
}
const hasHeaderDate = this.headerDateSlotItems.length ? 'header-date' : '';
return html`
<slot name="title" slot="title">
${this.resourceStrings.selectDate}
</slot>
<slot name="header-date" slot=${hasHeaderDate}></slot>
`;
}
private renderCalendar(id: string) {
const hideHeader = this.isDropDown ? true : this.hideHeader;
return html`
<igc-calendar
aria-labelledby=${id}
role="dialog"
.inert=${!this.open || this.disabled}
?show-week-numbers=${this.showWeekNumbers}
?hide-outside-days=${this.hideOutsideDays}
?hide-header=${hideHeader}
.activeDate=${this.activeDate ?? this.value}
.value=${this.value}
.headerOrientation=${this.headerOrientation}
.orientation=${this.orientation}
.visibleMonths=${this.visibleMonths}
.locale=${this.locale}
.disabledDates=${this._dateConstraints!}
.specialDates=${this.specialDates}
.weekStart=${this.weekStart}
@igcChange=${this.handleCalendarChangeEvent}
exportparts="header, header-title, header-date, content: calendar-content, navigation, months-navigation,
years-navigation, years-range, navigation-buttons, navigation-button, days-view-container,
days-view, months-view, years-view, days-row, label: calendar-label, week-number, week-number-inner, date,
date-inner, first, last, inactive, hidden, weekend, range, special, disabled, single, preview,
month, month-inner, year, year-inner, selected, current"
>
${this.renderCalendarSlots()}
</igc-calendar>
`;
}
protected renderActions() {
const slot = this.isDropDown || !this.actions.length ? undefined : 'footer';
// If in dialog mode use the dialog footer slot
return html`
<div
part="actions"
?hidden=${!this.actions.length}
slot=${ifDefined(slot)}
>
<slot name="actions"></slot>
</div>
`;
}
protected renderPicker(id: string) {
return this.isDropDown
? html`
<igc-popover ?open=${this.open} anchor=${id} flip shift>
<igc-focus-trap ?disabled=${!this.open || this.disabled}>
${this.renderCalendar(id)}${this.renderActions()}
</igc-focus-trap>
</igc-popover>
`
: html`
<igc-dialog
aria-label=${ifDefined(this.resourceStrings.selectDate)}
role="dialog"
?open=${this.open}
?close-on-outside-click=${!this.keepOpenOnOutsideClick}
hide-default-action
@igcClosing=${this.handleDialogClosing}
@igcClosed=${this.handleDialogClosed}
exportparts="base: dialog-base, title, footer, overlay"
>
${this.renderCalendar(id)}${this.renderActions()}
</igc-dialog>
`;
}
private renderLabel(id: string) {
return this.label
? html`<label
part="label"
for=${id}
@click=${this.isDropDown ? nothing : this.handleAnchorClick}
>${this.label}</label
>`
: nothing;
}
private renderHelperText(): TemplateResult {
return IgcValidationContainerComponent.create(this);
}
protected renderInput(id: string) {
const format = formats.has(this._displayFormat!)
? `${this._displayFormat}Date`
: this._displayFormat;
// Dialog mode is always readonly, rest depends on configuration
const readOnly = !this.isDropDown || this.readOnly || this.nonEditable;
return html`
<igc-date-time-input
id=${id}
aria-haspopup="dialog"
label=${ifDefined(this._isMaterialTheme ? this.label : undefined)}
input-format=${ifDefined(this._inputFormat)}
display-format=${ifDefined(format)}
?disabled=${this.disabled}
?readonly=${readOnly}
?required=${this.required}
.value=${this.value}
.locale=${this.locale}
.prompt=${this.prompt}
.outlined=${this.outlined}
.placeholder=${this.placeholder}
.min=${this.min}
.max=${this.max}
.invalid=${live(this.invalid)}
@igcChange=${this.handleInputChangeEvent}
@igcInput=${this.handleInputEvent}
@click=${this.isDropDown ? nothing : this.handleInputClick}
exportparts="input, label, prefix, suffix"
>
${this.renderCalendarIcon()}
<slot
name="prefix"
slot=${ifDefined(!this.prefixes.length ? undefined : 'prefix')}
></slot>
${this.renderClearIcon()}
<slot
name="suffix"
slot=${ifDefined(!this.suffixes.length ? undefined : 'suffix')}
></slot>
</igc-date-time-input>
`;
}
protected override render() {
const id = this.id || this.inputId;
return html`
${!this._isMaterialTheme ? this.renderLabel(id) : nothing}
${this.renderInput(id)}${this.renderPicker(id)}${this.renderHelperText()}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'igc-date-picker': IgcDatePickerComponent;
}
}