From e6ce75cb4d4433eca9d75ee9d34d63d2e18eb5aa Mon Sep 17 00:00:00 2001 From: Gregory Douglas <2968519+ggdouglas@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:57:43 -0400 Subject: [PATCH 1/2] Ensure createElement in Icon is never null --- packages/core/src/components/icon/icon.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/components/icon/icon.tsx b/packages/core/src/components/icon/icon.tsx index d74147797c..2d708d2668 100644 --- a/packages/core/src/components/icon/icon.tsx +++ b/packages/core/src/components/icon/icon.tsx @@ -171,7 +171,7 @@ export const Icon: IconComponent = React.forwardRef(function : size === IconSize.LARGE ? Classes.ICON_LARGE : undefined; - return React.createElement(tagName!, { + return React.createElement(tagName || "span", { "aria-hidden": title ? undefined : true, ...removeNonHTMLProps(htmlProps), className: classNames( From 2a3cffccfe5877194e534931dd275150c724db2b Mon Sep 17 00:00:00 2001 From: Gregory Douglas <2968519+ggdouglas@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:09:37 -0400 Subject: [PATCH 2/2] Update test to check for presence of span element --- packages/core/test/icon/iconTests.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/test/icon/iconTests.tsx b/packages/core/test/icon/iconTests.tsx index 211776bc10..613da644ec 100644 --- a/packages/core/test/icon/iconTests.tsx +++ b/packages/core/test/icon/iconTests.tsx @@ -132,7 +132,8 @@ describe("", () => { it("allows specifying the root element as when tagName={null}", () => { const handleClick: React.MouseEventHandler = () => undefined; - mount( icon="add" onClick={handleClick} tagName={null} />); + const wrapper = mount( icon="add" onClick={handleClick} tagName={null} />); + assert.isFalse(wrapper.find("span").exists()); }); /** Asserts that rendered icon has an SVG path. */