diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dc0cbf9c..bfd0b1c67 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -62,6 +62,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- ``
- `onSelection` now sets `newlySelected` only for add actions and no longer sets it to the last element
- border of the BlueprintJS `Tag` elements were fixed
+- ``
+ - badge is correctly displayed when `badge={0}`
- Focus outlines
- we use again bold focus outlines for input elements
- they are also used for clickable elements that are focused via keyboard (tab navigation)
diff --git a/src/components/Badge/Badge.test.tsx b/src/components/Badge/Badge.test.tsx
new file mode 100644
index 000000000..b3f5a0a9b
--- /dev/null
+++ b/src/components/Badge/Badge.test.tsx
@@ -0,0 +1,22 @@
+import React from "react";
+import { render } from "@testing-library/react";
+
+import "@testing-library/jest-dom";
+
+import { Badge } from "../../../index";
+import { CLASSPREFIX as eccgui } from "../../configuration/constants";
+
+describe("Badge", () => {
+ it("should shorten a number badge exceeding maxLength to a 9+ notation", () => {
+ const { container } = render({42});
+ const badge = container.querySelector(`.${eccgui}-badge__tag`);
+ expect(badge).not.toBeNull();
+ expect(badge).toHaveTextContent("9+");
+ });
+ it("should apply maxWidth style to a string badge when maxLength is set", () => {
+ const { container } = render(forty two);
+ const tag = container.querySelector(`.${eccgui}-badge__tag`);
+ expect(tag).not.toBeNull();
+ expect((tag as HTMLElement).style.maxWidth).toBe("calc((3em + 3ch)/2)");
+ });
+});
diff --git a/src/components/Button/Button.test.tsx b/src/components/Button/Button.test.tsx
index bc5763631..af853a11d 100644
--- a/src/components/Button/Button.test.tsx
+++ b/src/components/Button/Button.test.tsx
@@ -3,6 +3,7 @@ import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
+import { CLASSPREFIX as eccgui } from "../../configuration/constants";
import Icon from "../Icon/Icon";
import Button from "./Button";
@@ -21,7 +22,7 @@ describe("Button", () => {
);
expect(screen.getByRole("button").lastChild).toEqual(screen.getByText(/left icon/i));
- expect(container.getElementsByClassName("eccgui-icon").length).toBe(1);
+ expect(container.getElementsByClassName(`${eccgui}-icon`).length).toBe(1);
});
it("should have icon at the right after the text", () => {
@@ -31,6 +32,19 @@ describe("Button", () => {
);
expect(screen.getByRole("button").firstChild).toEqual(screen.getByText(/right icon/i));
- expect(container.getElementsByClassName("eccgui-icon").length).toBe(1);
+ expect(container.getElementsByClassName(`${eccgui}-icon`).length).toBe(1);
+ });
+
+ it("should render badge markup with correct content when used on an icon button", () => {
+ const { container } = render();
+ const badge = container.querySelector(`.${eccgui}-badge`);
+ expect(badge).not.toBeNull();
+ expect(badge).toHaveTextContent("badge content");
+ });
+ it("should render badge markup with correct content when batch displays a 0 (zero) number on an icon button", () => {
+ const { container } = render();
+ const badge = container.querySelector(`.${eccgui}-badge`);
+ expect(badge).not.toBeNull();
+ expect(badge).toHaveTextContent("0");
});
});
diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx
index 7110d1c33..153f4adab 100644
--- a/src/components/Button/Button.tsx
+++ b/src/components/Button/Button.tsx
@@ -113,7 +113,7 @@ export const Button = ({
rightIcon={typeof rightIcon === "string" ? : rightIcon}
>
{children}
- {badge && (
+ {typeof badge !== "undefined" && (