Skip to content

Commit 7c6f636

Browse files
committed
fix(date-input,time-input): fix invalidText property not being applied
1 parent ca21f28 commit 7c6f636

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@siemens/ix': patch
3+
---
4+
5+
Fix `invalidText` property not being applied to **ix-date-input** and **ix-time-input** when internal validation fails.
6+
7+
The `invalidText` property now correctly takes precedence over the i18n error messages when both are set. Previously, the i18n message would always be shown for internal validation errors (unparsable dates/times or min/max violations), ignoring the user's custom `invalidText`.
8+
9+
Fixes #2183.

packages/core/src/components/date-input/date-input.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ import {
3636
ValidationResults,
3737
createClassMutationObserver,
3838
} from '../utils/input';
39-
import { makeRef } from '../utils/make-ref';
40-
import type { DateInputValidityState } from './date-input.types';
4139
import {
4240
closeDropdown as closeDropdownUtil,
4341
createValidityState,
4442
handleIconClick,
4543
openDropdown as openDropdownUtil,
4644
} from '../utils/input/picker-input.util';
45+
import { makeRef } from '../utils/make-ref';
46+
import type { DateInputValidityState } from './date-input.types';
4747

4848
/**
4949
* @form-ready
@@ -484,7 +484,7 @@ export class DateInput implements IxInputFieldComponent<string | undefined> {
484484

485485
render() {
486486
const invalidText = this.isInputInvalid
487-
? this.i18nErrorDateUnparsable
487+
? this.invalidText || this.i18nErrorDateUnparsable
488488
: this.invalidText;
489489

490490
return (

packages/core/src/components/date-input/tests/date-input.ct.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,24 @@ regressionTest(
201201
await expect(input).not.toHaveClass(/is-invalid/);
202202
}
203203
);
204+
205+
regressionTest(
206+
'invalidText property takes precedence over i18n error message',
207+
async ({ mount, page }) => {
208+
await mount(
209+
`<ix-date-input value="2024/05/05" invalid-text="Custom error message"></ix-date-input>`
210+
);
211+
212+
const dateInputElement = page.locator('ix-date-input');
213+
214+
await expect(dateInputElement).toHaveClass(/hydrated/);
215+
await dateInputElement.locator('input').fill('invalid-date');
216+
await dateInputElement.locator('input').blur();
217+
await expect(
218+
dateInputElement
219+
.locator('ix-field-wrapper')
220+
.locator('ix-typography')
221+
.filter({ hasText: 'Custom error message' })
222+
).toHaveText('Custom error message');
223+
}
224+
);

packages/core/src/components/time-input/test/time-input.ct.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,25 @@ regressionTest.describe('time input tests', () => {
163163
await expect(input).not.toHaveClass(/is-invalid/);
164164
}
165165
);
166+
167+
regressionTest(
168+
'invalidText property takes precedence over i18n error message',
169+
async ({ mount, page }) => {
170+
await mount(
171+
`<ix-time-input value="09:10:11" format="HH:mm:ss" invalid-text="Custom time error"></ix-time-input>`
172+
);
173+
174+
const timeInputElement = page.locator('ix-time-input');
175+
176+
await expect(timeInputElement).toHaveClass(/hydrated/);
177+
await timeInputElement.locator('input').fill('invalid-time');
178+
await timeInputElement.locator('input').blur();
179+
await expect(
180+
timeInputElement
181+
.locator('ix-field-wrapper')
182+
.locator('ix-typography')
183+
.filter({ hasText: 'Custom time error' })
184+
).toHaveText('Custom time error');
185+
}
186+
);
166187
});

packages/core/src/components/time-input/time-input.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
h,
2323
} from '@stencil/core';
2424
import { DateTime } from 'luxon';
25+
import { IxTimePickerCustomEvent } from '../../components';
2526
import { SlotEnd, SlotStart } from '../input/input.fc';
2627
import {
2728
DisposableChangesAndVisibilityObservers,
@@ -36,15 +37,14 @@ import {
3637
ValidationResults,
3738
createClassMutationObserver,
3839
} from '../utils/input';
39-
import { makeRef } from '../utils/make-ref';
40-
import { IxTimePickerCustomEvent } from '../../components';
41-
import type { TimeInputValidityState } from './time-input.types';
4240
import {
4341
closeDropdown as closeDropdownUtil,
4442
createValidityState,
4543
handleIconClick,
4644
openDropdown as openDropdownUtil,
4745
} from '../utils/input/picker-input.util';
46+
import { makeRef } from '../utils/make-ref';
47+
import type { TimeInputValidityState } from './time-input.types';
4848

4949
/**
5050
* @since 3.2.0
@@ -498,7 +498,7 @@ export class TimeInput implements IxInputFieldComponent<string> {
498498

499499
render() {
500500
const invalidText = this.isInputInvalid
501-
? this.i18nErrorTimeUnparsable
501+
? this.invalidText || this.i18nErrorTimeUnparsable
502502
: this.invalidText;
503503

504504
return (

0 commit comments

Comments
 (0)