diff --git a/packages/nimble-components/src/table-column/enum-base/models/mapping-icon-config.ts b/packages/nimble-components/src/table-column/enum-base/models/mapping-icon-config.ts index 6a951516d8..38b63f1251 100644 --- a/packages/nimble-components/src/table-column/enum-base/models/mapping-icon-config.ts +++ b/packages/nimble-components/src/table-column/enum-base/models/mapping-icon-config.ts @@ -1,4 +1,4 @@ -import { html, when, type ViewTemplate } from '@microsoft/fast-element'; +import { html, type ViewTemplate } from '@microsoft/fast-element'; import type { IconSeverity } from '../../../icon-base/types'; import { MappingConfig } from './mapping-config'; @@ -6,23 +6,29 @@ export interface IconView { severity: IconSeverity; text?: string; } + +// Create an empty template containing only a space because creating a ViewTemplate +// with an empty string throws an exception at runtime. +const emptyTemplate = html` `; + const createIconTemplate = ( icon: string | undefined -): ViewTemplate => html` - ${when( - () => icon, - html` - <${icon!} +): ViewTemplate => { + if (icon === undefined) { + return emptyTemplate; + } + + return html` + <${icon} title="${x => x.text}" role="img" aria-label="${x => x.text}" severity="${x => x.severity}" class="no-shrink" > - - ` - )} -`; + + `; +}; /** * Mapping configuration corresponding to a icon mapping