Skip to content

Commit 8b5eef5

Browse files
committed
fix(drp): delegate validation on inputs switch; add test
1 parent 42d0450 commit 8b5eef5

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

src/components/date-range-picker/date-range-picker-two-inputs.form.spec.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
createFormAssociatedTestBed,
88
runValidationContainerTests,
99
simulateClick,
10+
simulateInput,
1011
} from '../common/utils.spec.js';
1112
import IgcDateTimeInputComponent from '../date-time-input/date-time-input.js';
13+
import IgcInputComponent from '../input/input.js';
1214
import IgcDateRangePickerComponent, {
1315
type DateRangeValue,
1416
} from './date-range-picker.js';
@@ -26,6 +28,7 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
2628

2729
const today = CalendarDay.today;
2830
const tomorrow = today.add('day', 1);
31+
const yesterday = today.add('day', -1);
2932

3033
const spec = createFormAssociatedTestBed<IgcDateRangePickerComponent>(
3134
html`<igc-date-range-picker
@@ -428,8 +431,6 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
428431
describe('Validation message slots', () => {
429432
it('', () => {
430433
const now = CalendarDay.today;
431-
const tomorrow = now.add('day', 1);
432-
const yesterday = now.add('day', -1);
433434

434435
const testParameters: ValidationContainerTestsParams<IgcDateRangePickerComponent>[] =
435436
[
@@ -467,4 +468,57 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
467468
runValidationContainerTests(IgcDateRangePickerComponent, testParameters);
468469
});
469470
});
471+
it('is correctly validated on switching between two and single inputs', async () => {
472+
spec.setProperties({ useTwoInputs: false });
473+
await elementUpdated(spec.element);
474+
475+
spec.setProperties({ value: null });
476+
spec.setProperties({ required: true });
477+
await elementUpdated(spec.element);
478+
479+
let singleInput = spec.element.renderRoot.querySelector(
480+
IgcInputComponent.tagName
481+
)!;
482+
expect(singleInput.invalid).to.be.true;
483+
484+
spec.setProperties({ useTwoInputs: true });
485+
await elementUpdated(spec.element);
486+
487+
const dti = spec.element.renderRoot.querySelectorAll(
488+
IgcDateTimeInputComponent.tagName
489+
);
490+
const input = dti[0]!.shadowRoot!.querySelector(
491+
'input'
492+
) as HTMLInputElement;
493+
simulateInput(input, { value: '01/01/2025', inputType: 'insertText' });
494+
// expect both inputs to be invalid as the date range is not complete
495+
expect(dti[0]!.invalid).to.be.true;
496+
expect(dti[1]!.invalid).to.be.true;
497+
498+
spec.setProperties({ useTwoInputs: false });
499+
await elementUpdated(spec.element);
500+
501+
spec.setProperties({
502+
disabledDates: [
503+
{
504+
type: DateRangeType.Between,
505+
dateRange: [today.native, tomorrow.native],
506+
},
507+
],
508+
});
509+
await elementUpdated(spec.element);
510+
511+
spec.setProperties({
512+
value: {
513+
start: today.add('day', -2).native,
514+
end: tomorrow.add('day', 2).native,
515+
},
516+
});
517+
await elementUpdated(spec.element);
518+
519+
singleInput = spec.element.renderRoot.querySelector(
520+
IgcInputComponent.tagName
521+
)!;
522+
expect(singleInput.invalid).to.be.true;
523+
});
470524
});

src/components/date-range-picker/date-range-picker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
633633
await this._calendar?.updateComplete;
634634
this._updateMaskedRangeValue();
635635
this._setCalendarRangeValues();
636+
this._delegateInputsValidity();
636637
}
637638

638639
@watch('mode')
@@ -1166,7 +1167,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
11661167
}
11671168

11681169
declare global {
1169-
interface HTMLElementTagNameMap {
1170+
interface HtmlElementTagNameMap {
11701171
'igc-date-range-picker': IgcDateRangePickerComponent;
11711172
}
11721173
}

0 commit comments

Comments
 (0)