Skip to content

Commit 8f41892

Browse files
authored
fix(setFormValue): accept empty strings like Chrome (#23)
1 parent fbd07ce commit 8f41892

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Diff for: src/element-internals.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ export class ElementInternals implements IElementInternals {
135135
return undefined;
136136
}
137137
removeHiddenInputs(this);
138-
if (value && !(value instanceof FormData)) {
138+
if (value != null && !(value instanceof FormData)) {
139139
if (ref.getAttribute('name')) {
140140
const hiddenInput = createHiddenInput(ref, this);
141141
hiddenInput.value = value;
142142
}
143-
} else if (value && value instanceof FormData) {
143+
} else if (value != null && value instanceof FormData) {
144144
value.forEach((formDataValue, formDataKey) => {
145145
if (typeof formDataValue === 'string') {
146146
const hiddenInput = createHiddenInput(ref, this);

Diff for: test/ElementInternals.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,17 @@ describe('The ElementInternals polyfill', () => {
355355
expect(document.activeElement).to.equal(el);
356356
});
357357

358-
if('will accept non strings', async () => {
358+
it('will accept non strings', async () => {
359359
internals.setFormValue(['a', 'b']);
360360
expect(
361361
new FormData(internals.form).get('foo')
362362
).to.equal('a,b');
363363
});
364+
365+
it('will accept empty strings', () => {
366+
internals.setFormValue('');
367+
expect(new FormData(internals.form).get('foo')).to.equal('');
368+
})
364369
});
365370

366371
describe('closed shadow root element', () => {

0 commit comments

Comments
 (0)