Skip to content

Commit 4d0438a

Browse files
committed
refactor(drp): some more code changes
1 parent 2c5caf1 commit 4d0438a

File tree

6 files changed

+29
-55
lines changed

6 files changed

+29
-55
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,8 @@ describe('Date range picker - single input', () => {
587587
picker.readOnly = true;
588588
await elementUpdated(picker);
589589

590-
input.focus();
591-
await elementUpdated(input);
592590
simulateClick(getIcon(picker, clearIcon));
593591
await elementUpdated(picker);
594-
input.blur();
595-
await elementUpdated(input);
596592

597593
expect(picker.value).to.deep.equal(testValue);
598594
expect(eventSpy).not.called;

src/components/date-range-picker/date-range-picker-single.validation.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('Date Range Picker Single Input - Form integration', () => {
4646
expect(spec.element.form).to.equal(spec.form);
4747
});
4848

49-
it('should not participate in form submission if the value is empty/invalid', async () => {
49+
it('should not participate in form submission if the value is empty/invalid', () => {
5050
value = { start: null, end: null };
5151
spec.setProperties({ value });
5252
spec.assertSubmitHasKeyValue('rangePicker', null);
@@ -76,7 +76,7 @@ describe('Date Range Picker Single Input - Form integration', () => {
7676
expect(input.value).to.equal('');
7777
});
7878

79-
it('should not be in invalid state on reset for a required control which previously had value', async () => {
79+
it('should not be in invalid state on reset for a required control which previously had value', () => {
8080
spec.setProperties({ value: value });
8181
spec.setProperties({ required: true });
8282

@@ -446,7 +446,7 @@ describe('Date Range Picker Single Input - Form integration', () => {
446446
endKey = `${spec.element.name}-end`;
447447
});
448448

449-
it('correct initial state', async () => {
449+
it('correct initial state', () => {
450450
spec.assertIsPristine();
451451
checkSelectedRange(spec.element, value, false);
452452
});
@@ -469,7 +469,7 @@ describe('Date Range Picker Single Input - Form integration', () => {
469469
});
470470
});
471471
describe('Validation message slots', () => {
472-
it('', async () => {
472+
it('', () => {
473473
const now = CalendarDay.today;
474474
const tomorrow = now.add('day', 1);
475475
const yesterday = now.add('day', -1);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,7 @@ describe('Date range picker - two inputs', () => {
608608
picker.readOnly = true;
609609
await elementUpdated(picker);
610610

611-
dateTimeInputs[0].focus();
612-
await elementUpdated(dateTimeInputs[0]);
613611
simulateClick(getIcon(picker, clearIcon));
614-
dateTimeInputs[0].blur();
615-
await elementUpdated(dateTimeInputs[0]);
616612

617613
expect(picker.value).to.deep.equal(testValue);
618614
expect(eventSpy).not.called;

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
simulateClick,
1010
} from '../common/utils.spec.js';
1111
import IgcDateTimeInputComponent from '../date-time-input/date-time-input.js';
12-
import IgcInputComponent from '../input/input.js';
1312
import IgcDateRangePickerComponent, {
1413
type DateRangeValue,
1514
} from './date-range-picker.js';
@@ -23,7 +22,7 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
2322
before(() => defineComponents(IgcDateRangePickerComponent));
2423

2524
let picker: IgcDateRangePickerComponent;
26-
let dateTimeInputs: Array<IgcDateTimeInputComponent>;
25+
let dateTimeInputs: IgcDateTimeInputComponent[];
2726

2827
const today = CalendarDay.today;
2928
const tomorrow = today.add('day', 1);
@@ -54,7 +53,7 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
5453
expect(spec.element.form).to.equal(spec.form);
5554
});
5655

57-
it('should not participate in form submission if the value is empty/invalid', async () => {
56+
it('should not participate in form submission if the value is empty/invalid', () => {
5857
value = { start: null, end: null };
5958
spec.setProperties({ value });
6059
spec.assertSubmitHasKeyValue(startKey, null);
@@ -380,24 +379,6 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
380379
expect(picker.invalid).to.be.false;
381380
await checkInputsInvalidState(picker, false, false);
382381
});
383-
384-
it('should not enter in invalid state when clicking the calendar toggle part - single input', async () => {
385-
picker = await fixture<IgcDateRangePickerComponent>(
386-
html`<igc-date-range-picker required></igc-date-range-picker>`
387-
);
388-
const input = picker.renderRoot.querySelector(
389-
IgcInputComponent.tagName
390-
) as IgcInputComponent;
391-
392-
expect(picker.invalid).to.be.false;
393-
expect(input.invalid).to.be.false;
394-
395-
simulateClick(getIcon(picker, toggleIcon));
396-
await elementUpdated(picker);
397-
398-
expect(picker.invalid).to.be.false;
399-
expect(input.invalid).to.be.false;
400-
});
401382
});
402383

403384
describe('defaultValue', () => {
@@ -422,7 +403,7 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
422403
endKey = `${spec.element.name}-end`;
423404
});
424405

425-
it('correct initial state', async () => {
406+
it('correct initial state', () => {
426407
spec.assertIsPristine();
427408
checkSelectedRange(spec.element, value);
428409
});
@@ -445,7 +426,7 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
445426
});
446427
});
447428
describe('Validation message slots', () => {
448-
it('', async () => {
429+
it('', () => {
449430
const now = CalendarDay.today;
450431
const tomorrow = now.add('day', 1);
451432
const yesterday = now.add('day', -1);

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
206206
delegatesFocus: true,
207207
};
208208

209-
private static readonly increment = createCounter();
210-
211209
/* blazorSuppress */
212210
public static register() {
213211
registerComponent(
@@ -226,6 +224,8 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
226224

227225
// #region Internal state & properties
228226

227+
private static readonly increment = createCounter();
228+
229229
protected inputId = `date-range-picker-${IgcDateRangePickerComponent.increment()}`;
230230
protected override _formValue: FormValue<DateRangeValue | null>;
231231

@@ -257,25 +257,25 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
257257
private _maskedRangeValue = '';
258258

259259
@queryAll(IgcDateTimeInputComponent.tagName)
260-
private _inputs!: IgcDateTimeInputComponent[];
260+
private readonly _inputs!: IgcDateTimeInputComponent[];
261261

262262
@query(IgcInputComponent.tagName)
263-
private _input!: IgcInputComponent;
263+
private readonly _input!: IgcInputComponent;
264264

265265
@query(IgcCalendarComponent.tagName)
266-
private _calendar!: IgcCalendarComponent;
266+
private readonly _calendar!: IgcCalendarComponent;
267267

268268
@queryAssignedElements({ slot: 'prefix' })
269-
private _prefixes!: HTMLElement[];
269+
private readonly _prefixes!: HTMLElement[];
270270

271271
@queryAssignedElements({ slot: 'suffix' })
272-
private _suffixes!: HTMLElement[];
272+
private readonly _suffixes!: HTMLElement[];
273273

274274
@queryAssignedElements({ slot: 'actions' })
275-
private _actions!: HTMLElement[];
275+
private readonly _actions!: HTMLElement[];
276276

277277
@queryAssignedElements({ slot: 'header-date' })
278-
private _headerDateSlotItems!: HTMLElement[];
278+
private readonly _headerDateSlotItems!: HTMLElement[];
279279

280280
// #endregion
281281

@@ -611,7 +611,12 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
611611

612612
/** Clears the input parts of the component of any user input */
613613
public clear() {
614-
this._clear(false);
614+
this._oldValue = this.value;
615+
this.value = null;
616+
if (this.useTwoInputs) {
617+
this._inputs[0]?.clear();
618+
this._inputs[1]?.clear();
619+
}
615620
}
616621

617622
/** Selects a date range value in the picker */
@@ -627,7 +632,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
627632
protected _openChange() {
628633
this._rootClickController.update();
629634

630-
if (this.open && this.mode === 'dialog') {
635+
if (this.open) {
631636
this._oldValue = this.value;
632637
}
633638
}
@@ -1040,16 +1045,12 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
10401045
}
10411046

10421047
protected _renderActions() {
1043-
const slot =
1044-
this._isDropDown || isEmpty(this._actions) ? undefined : 'footer';
1048+
const hasActions = !isEmpty(this._actions);
1049+
const slot = this._isDropDown || hasActions ? undefined : 'footer';
10451050

10461051
// If in dialog mode use the dialog footer slot
10471052
return html`
1048-
<div
1049-
part="actions"
1050-
?hidden=${isEmpty(this._actions)}
1051-
slot=${ifDefined(slot)}
1052-
>
1053+
<div part="actions" ?hidden=${!hasActions} slot=${ifDefined(slot)}>
10531054
<slot name="actions"></slot>
10541055
</div>
10551056
`;
@@ -1204,7 +1205,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
12041205
}
12051206

12061207
declare global {
1207-
interface HtmlElementTagNameMap {
1208+
interface HTMLElementTagNameMap {
12081209
'igc-date-range-picker': IgcDateRangePickerComponent;
12091210
}
12101211
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const checkSelectedRange = (
7575
const length = calendar.values.length;
7676
checkDatesEqual(calendar.values[length - 1], expectedValue?.end!);
7777
}
78-
if (!expectedValue?.start && !expectedValue?.end) {
78+
if (!(expectedValue?.start || expectedValue?.end)) {
7979
expect(calendar.values).to.deep.equal([]);
8080
}
8181
};

0 commit comments

Comments
 (0)