Skip to content

Commit de5cf72

Browse files
committed
fix: implement validity property for form controls
1 parent 205ceee commit de5cf72

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/uui-base/lib/mixins/FormControlMixin.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export declare abstract class FormControlMixinInterface extends LitElement {
1616
formResetCallback(): void;
1717
checkValidity(): boolean;
1818
get validationMessage(): string;
19+
get validity(): ValidityState;
1920
public setCustomValidity(error: string): void;
2021
protected _value: FormDataEntryValue | FormData;
2122
protected _internals: any;
@@ -302,6 +303,9 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
302303

303304
const hasError = Object.values(this._validityState).includes(true);
304305

306+
// https://developer.mozilla.org/en-US/docs/Web/API/ValidityState#valid
307+
this._validityState.valid = !hasError;
308+
305309
if (hasError) {
306310
this.dispatchEvent(
307311
new UUIFormControlEvent(UUIFormControlEvent.INVALID)
@@ -347,6 +351,11 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
347351
return this._internals?.checkValidity();
348352
}
349353

354+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
355+
public get validity(): ValidityState {
356+
return this._validityState;
357+
}
358+
350359
get validationMessage() {
351360
return this._internals?.validationMessage;
352361
}

0 commit comments

Comments
 (0)