@@ -15,12 +15,6 @@ import {
1515 StepMismatchError , BadInputError ,
1616} from './errors.js' ;
1717
18- export const ERRORS = {
19- AegisInputError, ValueMissingError, TypeMismatchError, PatternMismatchError,
20- TooLongError, TooShortError, RangeUnderflowError, RangeOverflowError,
21- StepMismatchError, BadInputError,
22- } ;
23-
2418/**
2519 * @see https://web.dev/articles/more-capable-form-controls
2620 */
@@ -31,9 +25,7 @@ export class AegisInput extends AegisComponent {
3125 role = 'textbox' ,
3226 ...rest
3327 } = { } ) {
34- if ( ! ( this [ SYMBOLS . sanitizeValue ] instanceof Function ) ) {
35- throw new Error ( `${ this . tagName . toLowerCase ( ) } does not have a [${ SYMBOLS . setValue . toString ( ) } ] method.` ) ;
36- } else if ( ! this [ SYMBOLS . initialized ] ) {
28+ if ( ! this [ SYMBOLS . initialized ] ) {
3729 const { shadow : s , internals : i } = await super [ SYMBOLS . initialize ] ( {
3830 role, ...rest ,
3931 } ) ;
@@ -77,17 +69,19 @@ export class AegisInput extends AegisComponent {
7769 const { internals, shadow } = protectedData . get ( this ) ;
7870
7971 try {
80- const result = await this [ SYMBOLS . sanitizeValue ] ( { value, internals, shadow } ) ;
81- this . #value = result ;
82- internals . setFormValue ( result ) ;
72+ const state = this [ SYMBOLS . sanitizeValue ] instanceof Function
73+ ? await this [ SYMBOLS . sanitizeValue ] ( { value, internals, shadow } )
74+ : value ;
75+ this . #value = state ;
76+ internals . setFormValue ( value , state ) ;
8377 internals . setValidity ( { } , '' ) ;
8478 internals . ariaInvalid = 'false' ;
8579 internals . states . delete ( STATES . invalid ) ;
8680 internals . states . add ( STATES . valid ) ;
8781 this . removeAttribute ( 'aria-errormessage' ) ;
8882
89- if ( typeof result === 'string' ) {
90- internals . ariaValueNow = result ;
83+ if ( typeof value === 'string' ) {
84+ internals . ariaValueNow = value ;
9185 }
9286
9387 this . dispatchEvent ( new Event ( EVENTS . valid ) ) ;
@@ -204,4 +198,44 @@ export class AegisInput extends AegisComponent {
204198 static get observedAttributes ( ) {
205199 return [ ...AegisComponent . observedAttributes , 'required' , 'disabled' , 'readonly' ] ;
206200 }
207- }
201+
202+ static get AegisInputError ( ) {
203+ return AegisInputError ;
204+ }
205+
206+ static get ValueMissingError ( ) {
207+ return ValueMissingError ;
208+ }
209+
210+ static get TypeMismatchError ( ) {
211+ return TypeMismatchError ;
212+ }
213+
214+ static get PatternMismatchError ( ) {
215+ return PatternMismatchError ;
216+ }
217+
218+ static get TooLongError ( ) {
219+ return TooLongError ;
220+ }
221+
222+ static get TooShortError ( ) {
223+ return TooShortError ;
224+ }
225+
226+ static get RangeUnderflowError ( ) {
227+ return RangeUnderflowError ;
228+ }
229+
230+ static get RangeOverflowError ( ) {
231+ return RangeOverflowError ;
232+ }
233+
234+ static get StepMismatchError ( ) {
235+ return StepMismatchError ;
236+ }
237+
238+ static get BadInputError ( ) {
239+ return BadInputError ;
240+ }
241+ }
0 commit comments