aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--web_src/js/utils/dom.test.ts4
-rw-r--r--web_src/js/utils/dom.ts2
2 files changed, 4 insertions, 2 deletions
diff --git a/web_src/js/utils/dom.test.ts b/web_src/js/utils/dom.test.ts
index d873484969..13df82d9b4 100644
--- a/web_src/js/utils/dom.test.ts
+++ b/web_src/js/utils/dom.test.ts
@@ -10,7 +10,9 @@ test('createElementFromAttrs', () => {
class: 'cls-1 cls-2',
'data-foo': 'the-data',
disabled: true,
+ checked: false,
required: null,
+ tabindex: 0,
});
- expect(el.outerHTML).toEqual('<button id="the-id" class="cls-1 cls-2" data-foo="the-data" disabled=""></button>');
+ expect(el.outerHTML).toEqual('<button id="the-id" class="cls-1 cls-2" data-foo="the-data" disabled="" tabindex="0"></button>');
});
diff --git a/web_src/js/utils/dom.ts b/web_src/js/utils/dom.ts
index 8d75c724de..82e7b755a5 100644
--- a/web_src/js/utils/dom.ts
+++ b/web_src/js/utils/dom.ts
@@ -297,7 +297,7 @@ export function createElementFromAttrs(tagName, attrs) {
const el = document.createElement(tagName);
for (const [key, value] of Object.entries(attrs)) {
if (value === undefined || value === null) continue;
- if (value === true) {
+ if (typeof value === 'boolean') {
el.toggleAttribute(key, value);
} else {
el.setAttribute(key, String(value));