Skip to content

Commit 14b0698

Browse files
fix: readOnly changes checkValidity
1 parent 9e2c3c8 commit 14b0698

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: src/element-internals.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ export class ElementInternals implements IElementInternals {
244244
get willValidate(): boolean {
245245
const ref = refMap.get(this);
246246
throwIfNotFormAssociated(ref, `Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element.`);
247-
if (ref.disabled || ref.hasAttribute('disabled')) {
247+
if (
248+
(ref.disabled || ref.hasAttribute('disabled')) ||
249+
ref.hasAttribute('readonly')
250+
) {
248251
return false;
249252
}
250253
return true;

Diff for: test/ElementInternals.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ describe('The ElementInternals polyfill', () => {
116116
expect(input.checkValidity()).to.be.true;
117117
});
118118

119+
it('checkValidity will be true if the element is readOnly', async () => {
120+
input.toggleAttribute('readonly', true);
121+
/** Inconsistent behavior in Chrome version, bug reported */
122+
if (ElementInternals.isPolyfilled) {
123+
expect(input.checkValidity()).to.be.true;
124+
}
125+
});
126+
119127
it('form should match form:invalid CSS selector when form-associated custom element is invalid', () => {
120128
expect(form.matches('form:is(:invalid, [internals-invalid])')).to.be.true;
121129
});

0 commit comments

Comments
 (0)