Skip to content

Commit 91b7fff

Browse files
committed
fix(date-inputs): Remove alwaysLeadingZero prop. Update tests.
1 parent 9bd1956 commit 91b7fff

File tree

8 files changed

+38
-107
lines changed

8 files changed

+38
-107
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('Date picker', () => {
5555

5656
beforeEach(async () => {
5757
picker = await fixture<IgcDatePickerComponent>(
58-
html`<igc-date-picker always-leading-zero></igc-date-picker>`
58+
html`<igc-date-picker></igc-date-picker>`
5959
);
6060
dateTimeInput = picker.renderRoot.querySelector(
6161
IgcDateTimeInputComponent.tagName
@@ -581,20 +581,26 @@ describe('Date picker', () => {
581581
it('should use the value of locale format for displayFormat, if it is not defined', async () => {
582582
expect(picker.locale).to.equal('en-US');
583583
expect(picker.getAttribute('display-format')).to.be.null;
584-
expect(picker.displayFormat).to.equal(picker.inputFormat);
584+
expect(picker.displayFormat).to.equal('M/d/yyyy');
585585

586586
// updates inputFormat according to changed locale
587587
picker.locale = 'fr';
588588
await elementUpdated(picker);
589589
expect(picker.inputFormat).to.equal('dd/MM/yyyy');
590-
expect(picker.displayFormat).to.equal(picker.inputFormat);
590+
expect(picker.displayFormat).to.equal('dd/MM/yyyy');
591591

592592
// sets inputFormat as attribute
593593
picker.setAttribute('input-format', 'dd-MM-yyyy');
594594
await elementUpdated(picker);
595595

596596
expect(picker.inputFormat).to.equal('dd-MM-yyyy');
597597
expect(picker.displayFormat).to.equal(picker.inputFormat);
598+
599+
// changing locale after setting input format shouldn't affect it
600+
picker.locale = 'de';
601+
await elementUpdated(picker);
602+
expect(picker.inputFormat).to.equal('dd-MM-yyyy');
603+
expect(picker.displayFormat).to.equal(picker.inputFormat);
598604
});
599605
});
600606

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,6 @@ export default class IgcDatePickerComponent extends FormAssociatedRequiredMixin(
420420
@property({ type: Boolean, reflect: true, attribute: 'show-week-numbers' })
421421
public showWeekNumbers = false;
422422

423-
/**
424-
* Sets to always show leading zero regardless of the displayFormat applied or one based on locale.
425-
* Leading zero is applied during edit for the inputFormat always, regardless of this option.
426-
* @attr
427-
*/
428-
@property({ type: Boolean, attribute: 'always-leading-zero' })
429-
public alwaysLeadingZero = false;
430-
431423
/**
432424
* Format to display the value in when not editing.
433425
* Defaults to the locale format if not set.
@@ -862,7 +854,6 @@ export default class IgcDatePickerComponent extends FormAssociatedRequiredMixin(
862854
label=${bindIf(this._isMaterial, this.label)}
863855
input-format=${ifDefined(this._inputFormat)}
864856
display-format=${ifDefined(format)}
865-
?always-leading-zero=${this.alwaysLeadingZero}
866857
?disabled=${this.disabled}
867858
?readonly=${readOnly}
868859
?required=${this.required}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Date range picker - single input', () => {
4242

4343
beforeEach(async () => {
4444
picker = await fixture<IgcDateRangePickerComponent>(
45-
html`<igc-date-range-picker always-leading-zero></igc-date-range-picker>`
45+
html`<igc-date-range-picker></igc-date-range-picker>`
4646
);
4747
input = picker.renderRoot.querySelector(IgcInputComponent.tagName)!;
4848

@@ -205,21 +205,21 @@ describe('Date range picker - single input', () => {
205205
});
206206

207207
it('should update the masked value with the locale', async () => {
208-
expect(picker.displayFormat).to.equal(picker.inputFormat);
208+
expect(picker.displayFormat).to.equal('M/d/yyyy');
209209

210210
picker.value = {
211211
start: CalendarDay.from(new Date(2025, 3, 9)).native,
212212
end: CalendarDay.from(new Date(2025, 3, 10)).native,
213213
};
214214
await elementUpdated(picker);
215215
const input = picker.renderRoot.querySelector(IgcInputComponent.tagName)!;
216-
expect(input.value).to.equal('04/09/2025 - 04/10/2025');
216+
expect(input.value).to.equal('4/9/2025 - 4/10/2025');
217217

218218
picker.locale = 'bg';
219219
await elementUpdated(picker);
220220

221221
expect(input.value.normalize('NFKC')).to.equal(
222-
'09.04.2025 г. - 10.04.2025 г.'
222+
'9.04.2025 г. - 10.04.2025 г.'
223223
);
224224
});
225225
it('should set the default placeholder of the single input to the input format (like dd/MM/yyyy - dd/MM/yyyy)', async () => {
@@ -238,7 +238,7 @@ describe('Date range picker - single input', () => {
238238
it('should set the mask of the single input per the display format (like dd/MM/yyyy - dd/MM/yyyy)', async () => {
239239
picker.useTwoInputs = false;
240240
await elementUpdated(picker);
241-
expect(picker.displayFormat).to.equal(picker.inputFormat);
241+
expect(picker.displayFormat).to.equal('M/d/yyyy');
242242

243243
picker.value = {
244244
start: CalendarDay.from(new Date(2025, 3, 9)).native,
@@ -247,7 +247,7 @@ describe('Date range picker - single input', () => {
247247
await elementUpdated(picker);
248248

249249
const input = picker.renderRoot.querySelector(IgcInputComponent.tagName)!;
250-
expect(input.value).to.equal('04/09/2025 - 04/10/2025');
250+
expect(input.value).to.equal('4/9/2025 - 4/10/2025');
251251

252252
picker.displayFormat = 'yyyy-MM-dd';
253253
await elementUpdated(picker);
@@ -264,7 +264,7 @@ describe('Date range picker - single input', () => {
264264
};
265265
await elementUpdated(picker);
266266

267-
expect(input.value).to.equal('04/09/2025 - 04/10/2025');
267+
expect(input.value).to.equal('4/9/2025 - 4/10/2025');
268268

269269
picker.clear();
270270
await elementUpdated(picker);
@@ -288,7 +288,7 @@ describe('Date range picker - single input', () => {
288288
start,
289289
end,
290290
});
291-
expect(input.value).to.equal('04/09/2025 - 04/10/2025');
291+
expect(input.value).to.equal('4/9/2025 - 4/10/2025');
292292
expect(eventSpy).not.called;
293293
});
294294
});

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

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,6 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
458458
@property()
459459
public prompt = '_';
460460

461-
/**
462-
* Sets to always show leading zero regardless of the displayFormat applied or one based on locale.
463-
* Leading zero is applied during edit for the inputFormat always, regardless of this option.
464-
* @attr
465-
*/
466-
@property({ type: Boolean, attribute: 'always-leading-zero' })
467-
public alwaysLeadingZero = false;
468-
469461
/**
470462
* Format to display the value in when not editing.
471463
* Defaults to the locale format if not set.
@@ -686,17 +678,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
686678
protected _updateDefaultMask(): void {
687679
this._defaultMask = DateTimeUtil.getDefaultInputMask(this.locale);
688680
this._defaultDisplayFormat = getDateFormatter().getLocaleDateTimeFormat(
689-
this.locale,
690-
this.alwaysLeadingZero
691-
);
692-
this._updateMaskedRangeValue();
693-
}
694-
695-
@watch('alwaysLeadingZero')
696-
protected _setAlwaysLeadingZero(): void {
697-
this._defaultDisplayFormat = getDateFormatter().getLocaleDateTimeFormat(
698-
this.locale,
699-
this.alwaysLeadingZero
681+
this.locale
700682
);
701683
this._updateMaskedRangeValue();
702684
}
@@ -914,18 +896,8 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
914896
const { start, end } = this.value;
915897
const displayFormat = predefinedToDateDisplayFormat(this.displayFormat);
916898

917-
const startValue = formatDisplayDate(
918-
start,
919-
this.locale,
920-
displayFormat,
921-
this.alwaysLeadingZero
922-
);
923-
const endValue = formatDisplayDate(
924-
end,
925-
this.locale,
926-
displayFormat,
927-
this.alwaysLeadingZero
928-
);
899+
const startValue = formatDisplayDate(start, this.locale, displayFormat);
900+
const endValue = formatDisplayDate(end, this.locale, displayFormat);
929901
this._maskedRangeValue =
930902
displayFormat || this.inputFormat
931903
? `${startValue} - ${endValue}`
@@ -1170,7 +1142,6 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
11701142
aria-haspopup="dialog"
11711143
input-format=${ifDefined(this._inputFormat)}
11721144
display-format=${ifDefined(format)}
1173-
?always-leading-zero=${this.alwaysLeadingZero}
11741145
?disabled=${this.disabled}
11751146
?readonly=${readOnly}
11761147
.value=${value ?? null}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ export const checkSelectedRange = (
5555
? DateTimeUtil.formatDisplayDate(
5656
expectedValue.start,
5757
picker.locale,
58-
picker.displayFormat,
59-
picker.alwaysLeadingZero
58+
picker.displayFormat
6059
)
6160
: '';
6261
const end = expectedValue?.end
6362
? DateTimeUtil.formatDisplayDate(
6463
expectedValue.end,
6564
picker.locale,
66-
picker.displayFormat,
67-
picker.alwaysLeadingZero
65+
picker.displayFormat
6866
)
6967
: '';
7068
expect(input.value).to.equal(`${start} - ${end}`);

src/components/date-time-input/date-time-input.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Date Time Input component', () => {
4141
describe('', async () => {
4242
beforeEach(async () => {
4343
el = await fixture<IgcDateTimeInputComponent>(
44-
html`<igc-date-time-input always-leading-zero></igc-date-time-input>`
44+
html`<igc-date-time-input></igc-date-time-input>`
4545
);
4646
input = el.renderRoot.querySelector('input')!;
4747
parser.prompt = defaultPrompt;
@@ -60,18 +60,20 @@ describe('Date Time Input component', () => {
6060
await elementUpdated(el);
6161
expect(el.placeholder).to.equal('dd.MM.yyyy');
6262
expect(el.inputFormat).to.equal('dd.MM.yyyy');
63+
expect(el.displayFormat).to.equal('d.M.yyyy');
6364
});
6465

6566
it('should update inputFormat with value according to locale', async () => {
6667
el.value = new Date(2020, 2, 3);
6768
await elementUpdated(el);
68-
expect(input.value).to.equal('03/03/2020');
69+
expect(input.value).to.equal('3/3/2020');
6970

7071
el.locale = 'no';
7172
await elementUpdated(el);
7273
expect(el.placeholder).to.equal('dd.MM.yyyy');
7374
expect(el.inputFormat).to.equal('dd.MM.yyyy');
74-
expect(input.value).to.equal('03.03.2020');
75+
expect(el.displayFormat).to.equal('d.M.yyyy');
76+
expect(input.value).to.equal('3.3.2020');
7577
});
7678

7779
it('should use inputFormat if no displayFormat is defined - issue 1114', async () => {
@@ -108,13 +110,12 @@ describe('Date Time Input component', () => {
108110
el.value = new Date(2020, 2, 3);
109111
await elementUpdated(el);
110112

111-
expect(input.value).to.equal('03/03/2020');
113+
expect(input.value).to.equal('3/3/2020');
112114

113115
el.displayFormat = 'dd.MM/yyyy';
114116
await elementUpdated(el);
115117
expect(input.value).to.equal('03.03/2020');
116118

117-
el.alwaysLeadingZero = false;
118119
el.displayFormat = 'd.M';
119120
await elementUpdated(el);
120121
expect(input.value).to.equal('3.3');
@@ -201,7 +202,7 @@ describe('Date Time Input component', () => {
201202
await elementUpdated(el);
202203

203204
expect(eventSpy).calledWith('igcChange');
204-
expect(input.value).to.deep.equal('01/01/2000');
205+
expect(input.value).to.deep.equal('1/1/2000');
205206
});
206207

207208
it('should correctly switch between different pre-defined date formats', async () => {
@@ -275,7 +276,7 @@ describe('Date Time Input component', () => {
275276
it('should clear input date on clear', async () => {
276277
el.value = new Date(2020, 2, 3);
277278
await elementUpdated(el);
278-
expect(input.value).to.equal('03/03/2020');
279+
expect(input.value).to.equal('3/3/2020');
279280

280281
el.clear();
281282
await elementUpdated(el);
@@ -831,7 +832,7 @@ describe('Date Time Input component', () => {
831832
it('Drop behavior', async () => {
832833
el.value = new Date(2020, 2, 3);
833834
await elementUpdated(el);
834-
expect(input.value).to.equal('03/03/2020');
835+
expect(input.value).to.equal('3/3/2020');
835836

836837
input.value = '1010';
837838
input.setSelectionRange(0, 4);

src/components/date-time-input/date-time-input.ts

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,6 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
175175
return this._max;
176176
}
177177

178-
/**
179-
* Sets to always show leading zero regardless of the displayFormat applied or one based on locale.
180-
* Leading zero is applied during edit for the inputFormat always, regardless of this option.
181-
* @attr
182-
*/
183-
@property({ type: Boolean, attribute: 'always-leading-zero' })
184-
public alwaysLeadingZero = false;
185-
186178
/**
187179
* Format to display the value in when not editing.
188180
* Defaults to the locale format if not set.
@@ -240,14 +232,6 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
240232
}
241233
}
242234

243-
@watch('alwaysLeadingZero', { waitUntilFirstUpdate: true })
244-
protected setAlwaysLeadingZero(): void {
245-
this.updateDefaultDisplayFormat();
246-
if (this.value) {
247-
this.updateMask();
248-
}
249-
}
250-
251235
@watch('displayFormat', { waitUntilFirstUpdate: true })
252236
protected setDisplayFormat(): void {
253237
this.updateDefaultDisplayFormat();
@@ -259,11 +243,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
259243
protected get hasDateParts(): boolean {
260244
const parts =
261245
this._inputDateParts ||
262-
DateTimeUtil.parseDateTimeFormat(
263-
this.inputFormat,
264-
this.locale,
265-
this.alwaysLeadingZero
266-
);
246+
DateTimeUtil.parseDateTimeFormat(this.inputFormat, this.locale);
267247

268248
return parts.some(
269249
(p) =>
@@ -276,11 +256,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
276256
protected get hasTimeParts(): boolean {
277257
const parts =
278258
this._inputDateParts ||
279-
DateTimeUtil.parseDateTimeFormat(
280-
this.inputFormat,
281-
this.locale,
282-
this.alwaysLeadingZero
283-
);
259+
DateTimeUtil.parseDateTimeFormat(this.inputFormat, this.locale);
284260
return parts.some(
285261
(p) =>
286262
p.type === DateParts.Hours ||
@@ -393,8 +369,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
393369
this._maskedValue = DateTimeUtil.formatDisplayDate(
394370
this.value,
395371
this.locale,
396-
this.displayFormat,
397-
this.alwaysLeadingZero
372+
this.displayFormat
398373
);
399374
}
400375
}
@@ -516,8 +491,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
516491

517492
private updateDefaultDisplayFormat(): void {
518493
this._defaultDisplayFormat = getDateFormatter().getLocaleDateTimeFormat(
519-
this.locale,
520-
this.alwaysLeadingZero
494+
this.locale
521495
);
522496
}
523497

0 commit comments

Comments
 (0)