Skip to content

Commit

Permalink
Pass aria attributes to pill (#2227)
Browse files Browse the repository at this point in the history
Previously, aria attributes were accepted as props, but nothing was done with them. I have passed the aria attributes to the `clickable` and the `view` so that they can be used.

Author: nedredmond

Reviewers: jeresig, jandrade

Required Reviewers:

Approved By: jeresig

Checks: ✅ codecov/project, ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Lint (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ gerald, ⏭️  dependabot

Pull Request URL: #2227
  • Loading branch information
nedredmond authored May 16, 2024
1 parent 52607c2 commit e8d25c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-frogs-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-blocks-pill": minor
---

Aria props are now properly applied to pill component.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("Pill", () => {
<Pill
id="pill-id"
role="radio"
aria-checked="true"
testId="pill-test-id"
onClick={() => {}}
ref={pillRef}
Expand All @@ -49,6 +50,7 @@ describe("Pill", () => {
expect(pillRef.current).toHaveAttribute("id", "pill-id");
expect(pillRef.current).toHaveAttribute("role", "radio");
expect(pillRef.current).toHaveAttribute("data-testid", "pill-test-id");
expect(pillRef.current).toHaveAttribute("aria-checked", "true");
});

test("is Clickable if onClick is passed in (mouse click)", async () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/wonder-blocks-pill/src/components/pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const Pill = React.forwardRef(function Pill(
onClick,
style,
testId,
...ariaProps
} = props;

let wrapperSizeStyle;
Expand Down Expand Up @@ -150,6 +151,7 @@ const Pill = React.forwardRef(function Pill(
style={[defaultStyles, colorStyles.clickableWrapper, style]}
testId={testId}
ref={ref as React.ForwardedRef<HTMLButtonElement>}
{...ariaProps}
>
{() => <PillInner size={size}>{children}</PillInner>}
</Clickable>
Expand All @@ -163,6 +165,7 @@ const Pill = React.forwardRef(function Pill(
style={[defaultStyles, style]}
testId={testId}
ref={ref as React.ForwardedRef<HTMLElement>}
{...ariaProps}
>
<PillInner size={size}>{children}</PillInner>
</View>
Expand Down

0 comments on commit e8d25c9

Please sign in to comment.