-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary testing of support and add implement new syntax #57
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ export function FormControlMixin< | |
*/ | ||
declare static formControlValidators: Validator[]; | ||
|
||
/** | ||
/** | ||
* If set to true the control described should be evaluated and validated | ||
* as part of a group. Like a radio, if any member of the group's validity | ||
* changes the the other members should update as well. | ||
|
@@ -35,7 +35,7 @@ export function FormControlMixin< | |
* validator will be evaluated whenever the host's required attribute | ||
* is updated. | ||
*/ | ||
static get observedAttributes(): string[] { | ||
static get observedAttributes(): string[] { | ||
const validatorAttributes = this.validators.map((validator) => validator.attribute).flat(); | ||
|
||
const observedAttributes = super.observedAttributes || []; | ||
|
@@ -286,10 +286,10 @@ export function FormControlMixin< | |
*/ | ||
declare validityCallback: (validationKey: string) => string | void; | ||
|
||
/** | ||
* Called when the control's validationMessage should be changed | ||
* @param message { string } - The new validation message | ||
*/ | ||
/** | ||
* Called when the control's validationMessage should be changed | ||
* @param message { string } - The new validation message | ||
*/ | ||
declare validationMessageCallback: (message: string) => void; | ||
|
||
/** | ||
|
@@ -318,7 +318,7 @@ export function FormControlMixin< | |
|
||
/** | ||
* Check to see if an error should be shown. This method will also | ||
* update the internals state object with the --show-error state | ||
* update the internals state object with the show-error state | ||
* if necessary. | ||
* @private | ||
*/ | ||
|
@@ -327,16 +327,23 @@ export function FormControlMixin< | |
return false; | ||
} | ||
|
||
const showError = this.#forceError || (this.#touched && !this.validity.valid && !this.#focused); | ||
const showError = this.#forceError || (this.#touched && !this.validity.valid && !this.#focused), | ||
states = this.internals.states, | ||
// Casted to any, because the polyfill forces dashed-ident syntax https://github.com/calebdwilliams/element-internals-polyfill/issues/126 | ||
// TODO: Remove any cast when the issue is resolved | ||
state: any = 'show-error'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove inaccurate type annotation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a comment and a TODO explaining why it's necessary. To make it work I should remove the |
||
|
||
/** | ||
* At the time of writing Firefox doesn't support states | ||
* TODO: Remove when check for states when fully support is in place | ||
*/ | ||
if (showError && this.internals.states) { | ||
this.internals.states.add('--show-error'); | ||
} else if (this.internals.states) { | ||
this.internals.states.delete('--show-error'); | ||
// https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet#compability_with_dashed-ident_syntax | ||
|
||
if (showError) { | ||
try { | ||
states.add(state); | ||
} catch { | ||
states.add(`--${state}`); | ||
} | ||
} else { | ||
states.delete(state); | ||
states.delete(`--${state}`); | ||
} | ||
|
||
return showError; | ||
|
@@ -419,12 +426,12 @@ export function FormControlMixin< | |
/** Once all the async validators have settled, resolve validationComplete */ | ||
Promise.allSettled(asyncValidators) | ||
.then(() => { | ||
/** Don't resolve validations if the signal is aborted */ | ||
if (!abortController?.signal.aborted) { | ||
this.#isValidationPending = false; | ||
this.#validationCompleteResolver?.(); | ||
} | ||
}); | ||
/** Don't resolve validations if the signal is aborted */ | ||
if (!abortController?.signal.aborted) { | ||
this.#isValidationPending = false; | ||
this.#validationCompleteResolver?.(); | ||
} | ||
}); | ||
|
||
/** | ||
* If async validators are present: | ||
|
@@ -484,7 +491,7 @@ export function FormControlMixin< | |
} | ||
} | ||
|
||
/** Reset control state when the form is reset */ | ||
/** Reset control state when the form is reset */ | ||
formResetCallback() { | ||
this.#touched = false; | ||
this.#forceError = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the type annotation it’s unnecessary and not accurate.