Skip to content

Commit

Permalink
expose tabindex on pill
Browse files Browse the repository at this point in the history
  • Loading branch information
nedredmond committed May 16, 2024
1 parent e8d25c9 commit fee9bfa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("Pill", () => {
id="pill-id"
role="radio"
aria-checked="true"
tabIndex={0}
testId="pill-test-id"
onClick={() => {}}
ref={pillRef}
Expand All @@ -51,6 +52,7 @@ describe("Pill", () => {
expect(pillRef.current).toHaveAttribute("role", "radio");
expect(pillRef.current).toHaveAttribute("data-testid", "pill-test-id");
expect(pillRef.current).toHaveAttribute("aria-checked", "true");
expect(pillRef.current).toHaveAttribute("tabindex", "0");
});

test("is Clickable if onClick is passed in (mouse click)", async () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/wonder-blocks-pill/src/components/pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ type Props = AriaProps & {
* Optional test ID for e2e testing.
*/
testId?: string;
/**
* The tab index of the pill (clickable only).
*/
tabIndex?: number;
};

const PillInner = (props: {
Expand Down Expand Up @@ -118,6 +122,7 @@ const Pill = React.forwardRef(function Pill(
onClick,
style,
testId,
tabIndex,
...ariaProps
} = props;

Expand Down Expand Up @@ -151,6 +156,7 @@ const Pill = React.forwardRef(function Pill(
style={[defaultStyles, colorStyles.clickableWrapper, style]}
testId={testId}
ref={ref as React.ForwardedRef<HTMLButtonElement>}
tabIndex={tabIndex}
{...ariaProps}
>
{() => <PillInner size={size}>{children}</PillInner>}
Expand Down

0 comments on commit fee9bfa

Please sign in to comment.