diff --git a/.changeset/popular-gifts-sing.md b/.changeset/popular-gifts-sing.md new file mode 100644 index 00000000000..ecfd89b5740 --- /dev/null +++ b/.changeset/popular-gifts-sing.md @@ -0,0 +1,5 @@ +--- +"@kaizen/components": patch +--- + +Fix issue in Button, where screen readers would announce the Button's contents on page-load. diff --git a/packages/components/src/Button/Button/_docs/Button.mdx b/packages/components/src/Button/Button/_docs/Button.mdx index 37bd152c1c4..c1cb469de4e 100644 --- a/packages/components/src/Button/Button/_docs/Button.mdx +++ b/packages/components/src/Button/Button/_docs/Button.mdx @@ -82,6 +82,11 @@ Alternatively use the `workingLabelHidden` prop to hide the button label all tog +### Controlling the working state +Here is an example of controlling whether the button is 'working' or not, using state. + + + ### Loading Use the LoadingInput component for button placeholders. diff --git a/packages/components/src/Button/Button/_docs/Button.stories.tsx b/packages/components/src/Button/Button/_docs/Button.stories.tsx index 8ff9a663d4a..c6c22e36bb3 100644 --- a/packages/components/src/Button/Button/_docs/Button.stories.tsx +++ b/packages/components/src/Button/Button/_docs/Button.stories.tsx @@ -1,4 +1,4 @@ -import React from "react" +import React, { useState } from "react" import { StoryObj, Meta } from "@storybook/react" import { AddIcon, ArrowRightIcon } from "~components/Icon" import { LoadingInput } from "~components/Loading" @@ -142,3 +142,29 @@ export const NativeFormButton: Story = { ), parameters: { controls: { disable: true } }, } + +export const ResolveWorking: Story = { + render: () => { + const [state, setState] = useState<"Ready" | "Working" | "Completed">( + "Ready" + ) + const handleClick = (): void => { + if (state === "Ready") { + setState("Working") + setTimeout(() => setState("Completed"), 3000) + } else { + setState("Ready") + } + } + + return ( + + )} + /> + ) + const button = getByTestId("id--generic-test") + const buttonContainer = button.parentElement + + expect(buttonContainer).toHaveAttribute("aria-live", "polite") + }) +}) diff --git a/packages/components/src/Button/GenericButton/GenericButton.tsx b/packages/components/src/Button/GenericButton/GenericButton.tsx index 5e4b623eb74..b7b94751b9f 100755 --- a/packages/components/src/Button/GenericButton/GenericButton.tsx +++ b/packages/components/src/Button/GenericButton/GenericButton.tsx @@ -129,7 +129,7 @@ export const GenericButton = forwardRef( styles.container, props.fullWidth && styles.fullWidth )} - aria-live="polite" + aria-live={"workingLabel" in props ? "polite" : undefined} > {determineButtonRenderer()}