Skip to content

Commit dbb3c1a

Browse files
authored
fix(setValidity): Added support for setting ValidityState from a native input as Chrome allows this (#25)
1 parent 0a25787 commit dbb3c1a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Diff for: src/element-internals.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,14 @@ export class ElementInternals implements IElementInternals {
166166
}
167167
validationAnchorMap.set(this, anchor);
168168
const validity = validityMap.get(this);
169-
if (Object.keys(validityChanges).length === 0) {
169+
const validityChangesObj = {};
170+
for (const key in validityChanges) {
171+
validityChangesObj[key] = validityChanges[key];
172+
}
173+
if (Object.keys(validityChangesObj).length === 0) {
170174
setValid(validity);
171175
}
172-
const check = { ...validity, ...validityChanges };
176+
const check = { ...validity, ...validityChangesObj };
173177
delete check.valid;
174178
const { valid } = reconcileValidty(validity, check);
175179

Diff for: test/ElementInternals.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ describe('The ElementInternals polyfill', () => {
232232
}).to.throw();
233233
});
234234

235+
it ('will accept ValidityState from a native form input', () => {
236+
el.input.required = true;
237+
el.input.reportValidity();
238+
internals.setValidity(el.input.validity, el.input.validationMessage, el.input);
239+
expect(internals.validity.valueMissing).to.be.true;
240+
});
241+
235242
it('will return true for willValidate if the field can participate in the form', () => {
236243
expect(internals.willValidate).to.be.true;
237244
});

0 commit comments

Comments
 (0)