From 040efa970c2cc965fb3830fbc12b2f623696dd9f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 16 Sep 2021 15:38:44 +0200 Subject: [PATCH] make className binding always have a value (may be undefined through T) --- src/platform/web/ui/general/html.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/web/ui/general/html.ts b/src/platform/web/ui/general/html.ts index db320017..1c51351f 100644 --- a/src/platform/web/ui/general/html.ts +++ b/src/platform/web/ui/general/html.ts @@ -17,7 +17,7 @@ limitations under the License. // DOM helper functions -export type ClassNames = { [className: string]: boolean | ((value?: T) => boolean) } +export type ClassNames = { [className: string]: boolean | ((value: T) => boolean) } export type BasicAttributes = { [attribute: string]: ClassNames | boolean | string } export type Child = string | Text | Element @@ -26,7 +26,7 @@ export function isChildren(children: object | Child | Child[]): children is Chil return typeof children !== "object" || "nodeType" in children || Array.isArray(children); } -export function classNames(obj: ClassNames, value?: T): string { +export function classNames(obj: ClassNames, value: T): string { return Object.entries(obj).reduce((cn, [name, enabled]) => { if (typeof enabled === "function") { enabled = enabled(value); @@ -70,7 +70,7 @@ export function elNS(ns: string, elementName: string, attributes?: BasicAttribut if (typeof value === "object") { // Only className should ever be an object; be careful // here anyway and ignore object-valued non-className attributes. - value = (value !== null && name === "className") ? classNames(value) : false; + value = (value !== null && name === "className") ? classNames(value, undefined) : false; } setAttribute(e, name, value); }