Skip to content

Commit 3afbc5a

Browse files
spike-rabbitkfenner
authored andcommitted
feat(forms): allow overriding of errormessage IDs on custom form controls
This will be used by si-formly to link error messages to the custom controls.
1 parent 2efd69f commit 3afbc5a

14 files changed

+91
-26
lines changed

projects/element-ng/datepicker/si-date-input.directive.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ export class SiDateInputDirective
108108
readonly readonly = input(false, { transform: booleanAttribute });
109109

110110
/**
111-
* Overrides the value of aria-describedby
111+
* This ID will be bound to the `aria-describedby` attribute of the date-input.
112+
* Use this to reference the element containing the error message(s) for the date-input.
113+
* It will be picked by the {@link SiFormItemComponent} if the date-input is used inside a form item.
112114
*
113115
* @defaultValue
114116
* ```

projects/element-ng/datepicker/si-date-range.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[siDatepickerConfig]="siDatepickerConfig()"
88
[placeholder]="startDatePlaceholder() | translate"
99
[attr.aria-label]="startDatePlaceholder() | translate"
10-
[errormessageId]="errormessageId"
10+
[errormessageId]="errormessageId()"
1111
[disabled]="disabled()"
1212
[readonly]="readonly()"
1313
(ngModelChange)="onInputChanged({ start: $event, end: value()?.end })"
@@ -22,7 +22,7 @@
2222
[siDatepickerConfig]="siDatepickerConfig()"
2323
[placeholder]="endDatePlaceholder() | translate"
2424
[attr.aria-label]="endDatePlaceholder() | translate"
25-
[errormessageId]="errormessageId"
25+
[errormessageId]="errormessageId()"
2626
[disabled]="disabled()"
2727
[readonly]="readonly()"
2828
(ngModelChange)="onInputChanged({ start: value()?.start, end: $event })"

projects/element-ng/datepicker/si-date-range.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,17 @@ export class SiDateRangeComponent
208208
*/
209209
readonly value = model<DateRange>();
210210

211-
/** @internal */
212-
readonly errormessageId = `${this.id()}-errormessage`;
211+
/**
212+
* This ID will be bound to the `aria-describedby` attribute of the date-range.
213+
* Use this to reference the element containing the error message(s) for the date-range.
214+
* It will be picked by the {@link SiFormItemComponent} if the date-range is used inside a form item.
215+
*
216+
* @defaultValue
217+
* ```
218+
* `${this.id()}-errormessage`
219+
* ```
220+
*/
221+
readonly errormessageId = input(`${this.id()}-errormessage`);
213222

214223
private validator!: ValidatorFn;
215224
private onChange = (val: any): void => {};

projects/element-ng/datepicker/si-timepicker.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
type="text"
1919
inputmode="numeric"
2020
[attr.aria-label]="config.ariaLabel | translate"
21-
[attr.aria-describedby]="errormessageId"
21+
[attr.aria-describedby]="errormessageId()"
2222
[attr.maxlength]="config.maxLength"
2323
[class.is-invalid]="!unitValidation()[config.name] || this.forceInvalid()"
2424
[disabled]="disabled()"
@@ -42,7 +42,7 @@
4242
#inputPart
4343
class="form-control"
4444
[attr.aria-label]="meridiansAriaLabel() | translate"
45-
[attr.aria-describedby]="errormessageId"
45+
[attr.aria-describedby]="errormessageId()"
4646
[class.readonly]="readonly()"
4747
[disabled]="disabled()"
4848
(change)="toggleMeridian()"

projects/element-ng/datepicker/si-timepicker.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,17 @@ export class SiTimepickerComponent implements ControlValueAccessor, SiFormItemCo
222222

223223
private readonly inputParts = viewChildren<ElementRef<HTMLElement>>('inputPart');
224224

225-
/** @internal */
226-
readonly errormessageId = `${this.id()}-errormessage`;
225+
/**
226+
* This ID will be bound to the `aria-describedby` attribute of the timepicker.
227+
* Use this to reference the element containing the error message(s) for the timepicker.
228+
* It will be picked by the {@link SiFormItemComponent} if the timepicker is used inside a form item.
229+
*
230+
* @defaultValue
231+
* ```
232+
* `${this.id()}-errormessage`
233+
* ```
234+
*/
235+
readonly errormessageId = input(`${this.id()}-errormessage`);
227236

228237
private onChange: (val: any) => void = () => {};
229238
private onTouched: () => void = () => {};

projects/element-ng/number-input/si-number-input.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[readonly]="readonly()"
88
[disabled]="disabled()"
99
[attr.aria-label]="ariaLabel() | translate"
10-
[attr.aria-describedby]="errormessageId"
10+
[attr.aria-describedby]="errormessageId()"
1111
[attr.placeholder]="placeholder() | translate"
1212
[attr.min]="min()"
1313
[attr.max]="max()"

projects/element-ng/number-input/si-number-input.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,17 @@ export class SiNumberInputComponent
141141

142142
readonly inputElement = viewChild.required<ElementRef<HTMLInputElement>>('inputElement');
143143

144-
/** @internal */
145-
readonly errormessageId = `${this.id()}-errormessage`;
144+
/**
145+
* This ID will be bound to the `aria-describedby` attribute of the number-input.
146+
* Use this to reference the element containing the error message(s) for the number-input.
147+
* It will be picked by the {@link SiFormItemComponent} if the number-input is used inside a form item.
148+
*
149+
* @defaultValue
150+
* ```
151+
* `${this.id()}-errormessage`
152+
* ```
153+
*/
154+
readonly errormessageId = input(`${this.id()}-errormessage`);
146155

147156
protected canInc = true;
148157
protected canDec = true;

projects/element-ng/phone-number/si-phone-number-input.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
type="tel"
7373
class="ms-4 border-0 p-0 focus-none shadow-none flex-grow-1 phone-number"
7474
[attr.aria-label]="phoneNumberAriaLabel() | translate"
75-
[attr.aria-describedby]="errormessageId"
75+
[attr.aria-describedby]="errormessageId()"
7676
[placeholder]="placeholder"
7777
[disabled]="disabled()"
7878
[readonly]="readonly()"

projects/element-ng/phone-number/si-phone-number-input.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,17 @@ export class SiPhoneNumberInputComponent
175175

176176
readonly valueChange = output<PhoneDetails>();
177177

178-
/** @internal */
179-
readonly errormessageId = `${this.id()}-errormessage`;
178+
/**
179+
* This ID will be bound to the `aria-describedby` attribute of the phone-number-input.
180+
* Use this to reference the element containing the error message(s) for the phone-number-input.
181+
* It will be picked by the {@link SiFormItemComponent} if the phone-number-input is used inside a form item.
182+
*
183+
* @defaultValue
184+
* ```
185+
* `${this.id()}-errormessage`
186+
* ```
187+
*/
188+
readonly errormessageId = input(`${this.id()}-errormessage`);
180189

181190
protected readonly phoneInput = viewChild.required<ElementRef<HTMLInputElement>>('phoneInput');
182191
protected selectedCountry?: CountryInfo;

projects/element-ng/pills-input/si-pills-input.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
'[attr.tabindex]': 'tabindex()',
5656
'[attr.aria-activedescendant]': 'activeDescendant()',
5757
'[attr.aria-labelledby]': 'labelledby()',
58-
'[attr.aria-describedby]': 'errormessageId'
58+
'[attr.aria-describedby]': 'errormessageId()'
5959
}
6060
})
6161
export class SiPillsInputComponent implements OnInit, ControlValueAccessor, SiFormItemControl {
@@ -109,8 +109,17 @@ export class SiPillsInputComponent implements OnInit, ControlValueAccessor, SiFo
109109
*/
110110
readonly labelledby = input(`${this.id()}-label`);
111111

112-
/** @internal */
113-
readonly errormessageId = `${this.id()}-errormessage`;
112+
/**
113+
* This ID will be bound to the `aria-describedby` attribute of the pills-input.
114+
* Use this to reference the element containing the error message(s) for the pills-input.
115+
* It will be picked by the {@link SiFormItemComponent} if the pills-input is used inside a form item.
116+
*
117+
* @defaultValue
118+
* ```
119+
* `${this.id()}-errormessage`
120+
* ```
121+
*/
122+
readonly errormessageId = input(`${this.id()}-errormessage`);
114123

115124
protected inputValue = '';
116125
protected onTouched: () => void = () => {};

0 commit comments

Comments
 (0)