diff --git a/apps/website/screens/components/status-light/code/StatusLightCodePage.tsx b/apps/website/screens/components/status-light/code/StatusLightCodePage.tsx index 849bd4c87b..404d7519b0 100644 --- a/apps/website/screens/components/status-light/code/StatusLightCodePage.tsx +++ b/apps/website/screens/components/status-light/code/StatusLightCodePage.tsx @@ -4,7 +4,6 @@ import DocFooter from "@/common/DocFooter"; import { TableCode } from "@/common/Code"; import Example from "@/common/example/Example"; import basicUsage from "./examples/basicUsage"; -import StatusBadge from "@/common/StatusBadge"; const sections = [ { @@ -21,16 +20,16 @@ const sections = [ + label - - - label - + string - string + An auxiliary text that will add some context to the status. It is the only accessible text of the + component: without it, the status light is only a colored dot and it must be accompanied by a visible + element or by surrounding context that explains its meaning. Screen readers only announce the status when + a label is provided. - An auxiliary text that will add some context to the status. - diff --git a/apps/website/screens/components/status-light/overview/StatusLightOverviewPage.tsx b/apps/website/screens/components/status-light/overview/StatusLightOverviewPage.tsx index e68a618211..4eab4e5829 100644 --- a/apps/website/screens/components/status-light/overview/StatusLightOverviewPage.tsx +++ b/apps/website/screens/components/status-light/overview/StatusLightOverviewPage.tsx @@ -32,7 +32,8 @@ const sections = [ easy recognition. - Label: a short text description alongside the status light to provide additional context. + Label (Optional): a short text description alongside the status light to provide additional + context. diff --git a/packages/lib/src/status-light/StatusLight.stories.tsx b/packages/lib/src/status-light/StatusLight.stories.tsx index 2803979d89..39da09c196 100644 --- a/packages/lib/src/status-light/StatusLight.stories.tsx +++ b/packages/lib/src/status-light/StatusLight.stories.tsx @@ -11,6 +11,7 @@ export default { const StatusLight = () => ( <> + <ExampleContainer> <Title title="Default light small" theme="light" level={4} /> <DxcStatusLight label="StatusLight" size="small" /> @@ -77,6 +78,68 @@ const StatusLight = () => ( <DxcStatusLight label="Very long label to try to force ellipsis" /> </DxcContainer> </ExampleContainer> + + <Title title="Without label" theme="light" level={2} /> + <ExampleContainer> + <Title title="Default light small" theme="light" level={4} /> + <DxcStatusLight size="small" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Default light medium" theme="light" level={4} /> + <DxcStatusLight /> + </ExampleContainer> + <ExampleContainer> + <Title title="Default light large" theme="light" level={4} /> + <DxcStatusLight size="large" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Info light small" theme="light" level={4} /> + <DxcStatusLight mode="info" size="small" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Info light medium" theme="light" level={4} /> + <DxcStatusLight mode="info" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Info light large" theme="light" level={4} /> + <DxcStatusLight mode="info" size="large" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Success light small" theme="light" level={4} /> + <DxcStatusLight mode="success" size="small" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Success lights medium" theme="light" level={4} /> + <DxcStatusLight mode="success" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Success lights large" theme="light" level={4} /> + <DxcStatusLight mode="success" size="large" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Warning light small" theme="light" level={4} /> + <DxcStatusLight mode="warning" size="small" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Warning light medium" theme="light" level={4} /> + <DxcStatusLight mode="warning" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Warning light large" theme="light" level={4} /> + <DxcStatusLight mode="warning" size="large" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Error light small" theme="light" level={4} /> + <DxcStatusLight mode="error" size="small" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Error lights medium" theme="light" level={4} /> + <DxcStatusLight mode="error" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Error lights large" theme="light" level={4} /> + <DxcStatusLight mode="error" size="large" /> + </ExampleContainer> </> ); diff --git a/packages/lib/src/status-light/StatusLight.test.tsx b/packages/lib/src/status-light/StatusLight.test.tsx index 81177e3bd5..4465896029 100644 --- a/packages/lib/src/status-light/StatusLight.test.tsx +++ b/packages/lib/src/status-light/StatusLight.test.tsx @@ -2,18 +2,15 @@ import { render } from "@testing-library/react"; import DxcStatusLight from "./StatusLight"; describe("StatusLight component tests", () => { - test("StatusLight renders with correct label", () => { - const { getByText } = render(<DxcStatusLight label="Status Light Test" />); - expect(getByText("Status Light Test")).toBeTruthy(); - }); - test("StatusLight renders with role 'status'", () => { - const { getByRole } = render(<DxcStatusLight label="Status Light Test" />); - expect(getByRole("status")).toBeTruthy(); + test("StatusLight with label has role status and shows the label", () => { + const { getByRole } = render(<DxcStatusLight label="Online" />); + const status = getByRole("status"); + expect(status.textContent).toBe("Online"); }); - test("StatusLight dot is aria-hidden", () => { - const { container } = render(<DxcStatusLight label="Hidden Dot Test" />); - const dot = container.querySelector("div[aria-hidden='true']"); - expect(dot).toBeTruthy(); + test("StatusLight without label has no status role, since there is nothing to announce", () => { + const { queryByRole, container } = render(<DxcStatusLight mode="error" />); + expect(queryByRole("status")).toBeNull(); + expect(container.querySelector("[aria-hidden='true']")).not.toBeNull(); }); }); diff --git a/packages/lib/src/status-light/StatusLight.tsx b/packages/lib/src/status-light/StatusLight.tsx index 7b1d000caf..2748ecf094 100644 --- a/packages/lib/src/status-light/StatusLight.tsx +++ b/packages/lib/src/status-light/StatusLight.tsx @@ -69,11 +69,13 @@ const Label = styled.span<{ export default function DxcStatusLight({ label, mode = "default", size = "medium" }: StatusLightProps) { return ( - <StatusLightContainer role="status" size={size}> + <StatusLightContainer role={label ? "status" : undefined} size={size}> <Dot mode={mode} size={size} aria-hidden="true" /> - <Label mode={mode} size={size}> - {label} - </Label> + {label && ( + <Label mode={mode} size={size}> + {label} + </Label> + )} </StatusLightContainer> ); } diff --git a/packages/lib/src/status-light/types.ts b/packages/lib/src/status-light/types.ts index e65c14650f..0fe3add3c4 100644 --- a/packages/lib/src/status-light/types.ts +++ b/packages/lib/src/status-light/types.ts @@ -6,9 +6,11 @@ export type StatusLightProps = { */ mode?: Mode; /** - * An auxiliar text that will add some context to the status. + * An auxiliar text that will add some context to the status. It is the only accessible text of the component: + * without it, the status light is only a colored dot and it must be accompanied by a visible element or by + * surrounding context that explains its meaning. Screen readers only announce the status when a label is provided. */ - label: string; + label?: string; /** * Size of the component. Should be defined based on its importance and/or available space. */