Skip to content

Commit e367835

Browse files
authored
Fix createElementFromAttrs bug (#31751)
The "false" value was not handled correctly, it would cause bugs in the future (fortunately, this behavior is not used in code yet).
1 parent d128352 commit e367835

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

web_src/js/utils/dom.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ test('createElementFromAttrs', () => {
1010
class: 'cls-1 cls-2',
1111
'data-foo': 'the-data',
1212
disabled: true,
13+
checked: false,
1314
required: null,
15+
tabindex: 0,
1416
});
15-
expect(el.outerHTML).toEqual('<button id="the-id" class="cls-1 cls-2" data-foo="the-data" disabled=""></button>');
17+
expect(el.outerHTML).toEqual('<button id="the-id" class="cls-1 cls-2" data-foo="the-data" disabled="" tabindex="0"></button>');
1618
});

web_src/js/utils/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export function createElementFromAttrs(tagName, attrs) {
297297
const el = document.createElement(tagName);
298298
for (const [key, value] of Object.entries(attrs)) {
299299
if (value === undefined || value === null) continue;
300-
if (value === true) {
300+
if (typeof value === 'boolean') {
301301
el.toggleAttribute(key, value);
302302
} else {
303303
el.setAttribute(key, String(value));

0 commit comments

Comments
 (0)