From 4c8aabecf9f9db9f9427ec7bca5cc52c99128c44 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 13 Feb 2023 15:14:26 +0100 Subject: Accept attribute undefined --- src/rx.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/rx.ts b/src/rx.ts index bf01b6d..2e91e56 100644 --- a/src/rx.ts +++ b/src/rx.ts @@ -32,7 +32,8 @@ interface Attributes { } type AttributeValue - = string + = undefined + | string | number | boolean | ((event: Event) => void) @@ -386,15 +387,15 @@ function appendNode(base: Element, node: Node, lastAdded?: Node) { } function setAttribute(state: State, element: Element, key: string, attribute: AttributeValue) { - if (typeof attribute == "boolean") { - if (attribute) { - // @ts-ignore - element[key] = "true" - } - } else if (typeof attribute == "number") { + if (attribute === undefined || attribute === false) { + // Do nothing + } else if (attribute === true) { + // @ts-ignore + element[key] = "true" + } else if (typeof attribute === "number") { // @ts-ignore element[key] = attribute.toString() - } else if (typeof attribute == "string") { + } else if (typeof attribute === "string") { // @ts-ignore element[key] = attribute } else { -- cgit v1.2.3