@@ -3,6 +3,7 @@ import type {
33 ReactiveController ,
44 ReactiveControllerHost ,
55} from 'lit' ;
6+ import type { FormValueType } from '../mixins/forms/types.js' ;
67
78/** Configuration for the ElementInternalsController. */
89type ElementInternalsConfig < T extends keyof ARIAMixin = keyof ARIAMixin > = {
@@ -29,6 +30,41 @@ class ElementInternalsController {
2930 return this . _internals . form ;
3031 }
3132
33+ /**
34+ * Returns a `ValidityState` object which represents the different validity states
35+ * the element can be in, with respect to constraint validation.
36+ *
37+ * @remarks
38+ * The host element must be form associated, that is should have
39+ * `static formAssociated = true`.
40+ */
41+ public get validity ( ) : ValidityState {
42+ return this . _internals . validity ;
43+ }
44+
45+ /**
46+ * Returns a string containing the validation message of this element.
47+ *
48+ * @remarks
49+ * The host element must be form associated, that is should have
50+ * `static formAssociated = true`.
51+ */
52+ public get validationMessage ( ) : string {
53+ return this . _internals . validationMessage ;
54+ }
55+
56+ /**
57+ * Returns a boolean value which returns true if the element is a submittable element
58+ * which is a candidate for constraint validation.
59+ *
60+ * @remarks
61+ * The host element must be form associated, that is should have
62+ * `static formAssociated = true`.
63+ */
64+ public get willValidate ( ) : boolean {
65+ return this . _internals . willValidate ;
66+ }
67+
3268 constructor (
3369 host : ReactiveControllerHost & LitElement ,
3470 config ?: ElementInternalsConfig
@@ -52,13 +88,29 @@ class ElementInternalsController {
5288
5389 /**
5490 * Adds or removes a custom state from the element's internals.
55- * Custom states can be styled via `:state()` pseudo-class in CSS.
91+ * Custom states can be styled via `:state()` selector in CSS.
5692 */
5793 public setState ( state : string , value : boolean ) : void {
5894 value
5995 ? this . _internals . states . add ( state )
6096 : this . _internals . states . delete ( state ) ;
6197 }
98+
99+ public setFormValue ( value : FormValueType , state ?: FormValueType ) : void {
100+ this . _internals . setFormValue ( value , state ) ;
101+ }
102+
103+ public setValidity ( flags ?: ValidityStateFlags , message ?: string ) : void {
104+ this . _internals . setValidity ( flags , message ) ;
105+ }
106+
107+ public checkValidity ( ) : boolean {
108+ return this . _internals . checkValidity ( ) ;
109+ }
110+
111+ public reportValidity ( ) : boolean {
112+ return this . _internals . reportValidity ( ) ;
113+ }
62114}
63115
64116/** Creates and adds a {@link ElementInternalsController} to a LitElement host. */
0 commit comments