Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(button): add check for workingLabel to GenericButton for aria-live #39

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/stale-crabs-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@kaizen/button": patch
---

Fix aria-polite presence on buttons without working states.
* The aria-live="polite" will only be added when a workingLabel is provided to the button.
* This will mean the content should only be read when inner content updates on buttons with working states
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exports[`Dropdown renders default view 1`] = `
class="buttonWrapper"
>
<span
aria-live="polite"
class="container"
>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ exports[`<InformationTile /> snapshots renders InformationTile with information
class="informationBtn"
>
<span
aria-live="polite"
class="container"
>
<button
Expand Down Expand Up @@ -259,7 +258,6 @@ exports[`<InformationTile /> snapshots renders InformationTile with information
class="informationBtn"
>
<span
aria-live="polite"
class="container"
>
<button
Expand Down Expand Up @@ -305,7 +303,6 @@ exports[`<InformationTile /> snapshots renders InformationTile with information
class="actions"
>
<span
aria-live="polite"
class="container"
>
<button
Expand Down Expand Up @@ -543,7 +540,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile 1`] = `
class="actions"
>
<span
aria-live="polite"
class="container"
>
<a
Expand Down Expand Up @@ -610,7 +606,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with assertive mo
class="p-0 mr-0-point-5"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -631,7 +626,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with assertive mo
</span>
</div>
<span
aria-live="polite"
class="container"
>
<a
Expand Down Expand Up @@ -698,7 +692,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with cautionary m
class="p-0 mr-0-point-5"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -719,7 +712,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with cautionary m
</span>
</div>
<span
aria-live="polite"
class="container"
>
<a
Expand Down Expand Up @@ -786,7 +778,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with informative
class="p-0 mr-0-point-5"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -807,7 +798,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with informative
</span>
</div>
<span
aria-live="polite"
class="container"
>
<a
Expand Down Expand Up @@ -874,7 +864,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with negative moo
class="p-0 mr-0-point-5"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -895,7 +884,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with negative moo
</span>
</div>
<span
aria-live="polite"
class="container"
>
<a
Expand Down Expand Up @@ -962,7 +950,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with positive moo
class="p-0 mr-0-point-5"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -983,7 +970,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with positive moo
</span>
</div>
<span
aria-live="polite"
class="container"
>
<a
Expand Down Expand Up @@ -1050,7 +1036,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with prominent mo
class="p-0 mr-0-point-5"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -1071,7 +1056,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with prominent mo
</span>
</div>
<span
aria-live="polite"
class="container"
>
<a
Expand Down Expand Up @@ -1138,7 +1122,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with secondary ac
class="p-0 mr-0-point-5"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -1159,7 +1142,6 @@ exports[`<MultiActionTile /> snapshots renders MultiActionTile with secondary ac
</span>
</div>
<span
aria-live="polite"
class="container"
>
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ exports[`<BrandMoment /> matches the snapshot 1`] = `
/>
</video>
<span
aria-live="polite"
class="container"
>
<button
Expand Down Expand Up @@ -113,7 +112,6 @@ exports[`<BrandMoment /> matches the snapshot 1`] = `
class="actions"
>
<span
aria-live="polite"
class="container"
>
<a
Expand All @@ -136,7 +134,6 @@ exports[`<BrandMoment /> matches the snapshot 1`] = `
class="secondaryAction"
>
<span
aria-live="polite"
class="container"
>
<a
Expand Down
69 changes: 69 additions & 0 deletions packages/button/src/Button/components/GenericButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,72 @@ describe("<GenericButton /> with native HTML `form` attributes", () => {
).toHaveAttribute("form", buttonFormAttributes.form)
})
})

describe("<GenericButton /> `working` accessible states", () => {
it("renders a button without aria-live by default", () => {
const { getByTestId } = render(
<GenericButton
data-testid="id--generic-test"
id="id--button"
label="button label"
/>
)

const button = getByTestId("id--generic-test")
// The id is passed to the element not the container so we have to get its parent
const buttonContainer = button.parentElement

expect(buttonContainer).not.toHaveAttribute("aria-live", "")
})

it("renders a button with aria-live if working label if provided", () => {
const { getByTestId } = render(
<GenericButton
data-testid="id--generic-test"
id="id--button"
label="button label"
workingLabel="Loading"
/>
)
const button = getByTestId("id--generic-test")
const buttonContainer = button.parentElement

expect(buttonContainer).toHaveAttribute("aria-live", "polite")
})

it("renders a link button with aria-live if working label if provided", () => {
const { getByTestId } = render(
<GenericButton
data-testid="id--generic-test"
id="id--button"
label="button label"
workingLabel="Loading"
href="/"
/>
)
const button = getByTestId("id--generic-test")
const buttonContainer = button.parentElement

expect(buttonContainer).toHaveAttribute("aria-live", "polite")
})

it("renders a custom button with aria-live if working label if provided", () => {
const { getByTestId } = render(
<GenericButton
data-testid="id--generic-test"
id="id--button"
label="button label"
workingLabel="Loading"
component={props => (
<button type="button" {...props}>
Custom button
</button>
)}
/>
)
const button = getByTestId("id--generic-test")
const buttonContainer = button.parentElement

expect(buttonContainer).toHaveAttribute("aria-live", "polite")
})
})
3 changes: 2 additions & 1 deletion packages/button/src/Button/components/GenericButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type WorkingProps = {

export type WorkingUndefinedProps = {
working?: false
workingLabel?: string
}

type Props = ButtonProps & {
Expand Down Expand Up @@ -116,7 +117,7 @@ const GenericButton = forwardRef(
styles.container,
props.fullWidth && styles.fullWidth
)}
aria-live="polite"
aria-live={props.workingLabel ? "polite" : undefined}
>
{determineButtonRenderer()}
</span>
Expand Down