Skip to content

Commit 6cd1b6d

Browse files
fix: fix form initialization
1 parent d2552e7 commit 6cd1b6d

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Diff for: src/ValidityState.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { setFormValidity } from "./utils";
2+
13
/** Emulate the browser's default ValidityState object */
24
export class ValidityState implements globalThis.ValidityState {
35
badInput = false;
@@ -43,9 +45,12 @@ export const setValid = (validityObject: ValidityState): ValidityState => {
4345
* @param {Object} - A partial ValidityState object to override the original
4446
* @return {ValidityState} - The updated ValidityState object
4547
*/
46-
export const reconcileValidity = (validityObject: ValidityState, newState: Partial<ValidityState>): ValidityState => {
48+
export const reconcileValidity = (validityObject: ValidityState, newState: Partial<ValidityState>, form: HTMLFormElement): ValidityState => {
4749
validityObject.valid = isValid(newState);
4850
Object.keys(newState).forEach(key => validityObject[key] = newState[key]);
51+
if (form) {
52+
setFormValidity(form);
53+
}
4954
return validityObject;
5055
};
5156

Diff for: src/element-internals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class ElementInternals implements IElementInternals {
205205
}
206206
const check = { ...validity, ...validityChangesObj };
207207
delete check.valid;
208-
const { valid } = reconcileValidity(validity, check);
208+
const { valid } = reconcileValidity(validity, check, this.form);
209209

210210
if (!valid && !validationMessage) {
211211
throw new DOMException(`Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.`);

Diff for: src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface ICustomElement extends HTMLElement {
7777
disabled?: boolean;
7878
}
7979

80-
export type LabelsList = NodeList & [];
80+
export type LabelsList = NodeListOf<HTMLLabelElement>;
8181

8282
declare global {
8383
interface HTMLElement {

0 commit comments

Comments
 (0)