Skip to content

Commit 366c43c

Browse files
fix: polyfill now respects willValidate for check and report validity
1 parent 9983eb2 commit 366c43c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: src/element-internals.ts

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export class ElementInternals implements IElementInternals {
100100
checkValidity(): boolean {
101101
const ref = refMap.get(this);
102102
throwIfNotFormAssociated(ref, `Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
103+
/** If the element will not validate, it is necessarily valid by default */
104+
if (!this.willValidate) {
105+
return true;
106+
}
103107
const validity = validityMap.get(this);
104108
if (!validity.valid) {
105109
const validityEvent = new Event('invalid', {
@@ -139,6 +143,10 @@ export class ElementInternals implements IElementInternals {
139143
reportValidity(): boolean {
140144
const ref = refMap.get(this);
141145
throwIfNotFormAssociated(ref, `Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
146+
/** If the element will not validate, it is valid by default */
147+
if (!this.willValidate) {
148+
return true;
149+
}
142150
const valid = this.checkValidity();
143151
const anchor = validationAnchorMap.get(this);
144152
if (anchor && !ref.constructor['formAssociated']) {

Diff for: test/ElementInternals.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ describe('The ElementInternals polyfill', () => {
111111
expect(form.checkValidity()).to.be.false;
112112
});
113113

114+
it('checkValidity will be true if the element is disabled', () => {
115+
input.toggleAttribute('disabled', true);
116+
expect(input.checkValidity()).to.be.true;
117+
});
118+
114119
it('form should match form:invalid CSS selector when form-associated custom element is invalid', () => {
115120
expect(form.matches('form:is(:invalid, [internals-invalid])')).to.be.true;
116121
});

0 commit comments

Comments
 (0)