Conversation
…nput; add test for both input modes
There was a problem hiding this comment.
Pull request overview
This pull request adds a new IgcDateRangeInputComponent to enable editable date range input in single-input mode for the date range picker. The implementation involves refactoring the existing IgcDateTimeInputComponent by extracting common functionality into a new IgcDateTimeInputBaseComponent base class that uses generic type parameters to support both single date values and date ranges.
Changes:
- Extracted
IgcDateTimeInputBaseComponentas a generic base class for date/time input components - Created new
IgcDateRangeInputComponentfor editable date range input with mask support - Updated
IgcDateRangePickerComponentto use the new date range input component in single-input mode - Updated story files to document DateRangeValue type (though with incorrect additions to non-date components)
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/date-time-input/date-time-input.base.ts | New generic base class extracted from date-time-input, providing common functionality for date/time inputs |
| src/components/date-time-input/date-time-input.ts | Refactored to extend the new base class, removing duplicate code |
| src/components/date-range-picker/date-range-input.ts | New component implementing editable date range input with mask parsing and formatting |
| src/components/date-range-picker/date-range-picker.ts | Updated to integrate the new date-range-input component and handle its events |
| src/components/date-time-input/date-util.ts | Added DateRangePosition enum and DateRangePart interfaces for range-specific logic |
| src/index.ts | Updated export path for IgcDateTimeInputComponentEventMap |
| stories/*.stories.ts | Updated type definitions (with errors for non-date components) |
| Test files | Updated to use and test the new date-range-input component |
| this._inputs[0]?.clear(); | ||
| this._inputs[1]?.clear(); | ||
| } else { | ||
| this._input.value = null; |
There was a problem hiding this comment.
Line 633 is redundant. The value is already being set to null by line 628 (this.value = null), and then line 634 calls clear() which also sets the value to null. Consider removing line 633 as it's unnecessary duplication.
| this._input.value = null; |
| rangeInput = picker.renderRoot.querySelector( | ||
| IgcDateRangeInputComponent.tagName | ||
| )!; | ||
| rangeInput.renderRoot.querySelector('input')!; |
There was a problem hiding this comment.
This line queries for an input element but doesn't assign it to the input variable declared on line 42. This appears to be incomplete code. Consider removing this line or assigning the result to the input variable: input = rangeInput.renderRoot.querySelector('input')!;
| rangeInput.renderRoot.querySelector('input')!; | |
| input = rangeInput.renderRoot.querySelector('input')!; |
stories/input.stories.ts
Outdated
| /** The value of the control. */ | ||
| value: string | Date; | ||
| value: string | Date | DateRangeValue; |
There was a problem hiding this comment.
The type annotation is incorrect. IgcInputComponent only accepts string values, not DateRangeValue. This interface should match the actual component implementation where value is of type string.
| value: { | ||
| type: 'string | Date | DateRangeValue', | ||
| description: 'The value of the input.', | ||
| options: ['string', 'Date', 'DateRangeValue'], | ||
| control: 'text', |
There was a problem hiding this comment.
The type annotation is incorrect. IgcDateTimeInputComponent accepts Date | string | null, not DateRangeValue. The value property in the component is of type Date | null. This should be reverted to type: 'string | Date' and the DateRangeValue option removed from the options array.
stories/date-time-input.stories.ts
Outdated
| /** The value of the input. */ | ||
| value: string | Date | DateRangeValue; |
There was a problem hiding this comment.
The type annotation is incorrect. IgcDateTimeInputComponent accepts Date | string | null, not DateRangeValue. This interface should match the actual component implementation.
stories/file-input.stories.ts
Outdated
| /** The value of the control. */ | ||
| value: string | Date; | ||
| value: string | Date | DateRangeValue; |
There was a problem hiding this comment.
The type annotation is incorrect. IgcFileInputComponent only accepts string values, not DateRangeValue. This interface should match the actual component implementation.
| ?invalid=${live(this.invalid)} | ||
| .disabled=${this.disabled} | ||
| .inputFormat=${live(this.inputFormat)} | ||
| .displayFormat=${live(format)} |
There was a problem hiding this comment.
The igc-date-range-input component is missing the .locale and .prompt properties that are being passed to the igc-date-time-input components in the two-input mode (see lines 1133-1134). These properties should be passed to ensure consistent behavior between single and two-input modes.
| .displayFormat=${live(format)} | |
| .displayFormat=${live(format)} | |
| .locale=${this.locale} | |
| .prompt=${this.prompt} |
| ?invalid=${live(this.invalid)} | ||
| .disabled=${this.disabled} | ||
| .inputFormat=${live(this.inputFormat)} | ||
| .displayFormat=${live(format)} |
There was a problem hiding this comment.
The igc-date-range-input component is missing the .min and .max properties that are being passed to the igc-date-time-input components in the two-input mode (see lines 1137-1138). These properties should be passed to ensure date validation works consistently between single and two-input modes.
| .displayFormat=${live(format)} | |
| .displayFormat=${live(format)} | |
| .min=${this.min} | |
| .max=${this.max} |
stories/input.stories.ts
Outdated
| value: { | ||
| type: 'string | Date', | ||
| type: 'string | Date | DateRangeValue', | ||
| description: 'The value of the control.', | ||
| options: ['string', 'Date'], | ||
| options: ['string', 'Date', 'DateRangeValue'], |
There was a problem hiding this comment.
The type annotation is incorrect. IgcInputComponent only accepts string values, not DateRangeValue. The value property is defined as string in the component implementation. This should be reverted to type: 'string' and the DateRangeValue option removed from the options array.
| } | ||
|
|
||
| protected setToday() { | ||
| this.value = new Date() as TValue; |
There was a problem hiding this comment.
The setToday method casts new Date() to TValue, but when TValue is DateRangeValue | null, this cast is incorrect. For date range inputs, setting today should create a range with both start and end set to today. Consider making this method abstract and implementing it in the concrete classes, or add logic to check the value type and handle DateRangeValue appropriately.
| this.value = new Date() as TValue; | |
| const today = new Date(); | |
| const currentValue = this.value as unknown; | |
| if ( | |
| currentValue !== null && | |
| typeof currentValue === 'object' && | |
| 'start' in currentValue && | |
| 'end' in currentValue | |
| ) { | |
| this.value = { start: today, end: today } as TValue; | |
| } else { | |
| this.value = today as TValue; | |
| } |
b58c49d to
3a366f7
Compare
Adds a new
IgcDateRangeInputComponentto be used by theIgcDateRangePicker, which would allow to edit date range by typing in singe-input mode as well.