Skip to content

Commit

Permalink
tabs: use type button by default (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chance Strickland committed May 11, 2020
2 parents a7d444a + aa82a1c commit e17d904
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/tabs/__tests__/tabs.test.tsx
Expand Up @@ -13,6 +13,46 @@ import {
} from "@reach/tabs";

describe("<Tabs />", () => {
describe("rendering", () => {
it("sets the button type to button by default", () => {
const { getByText } = render(
<div>
<Tabs>
<TabList>
<Tab>Tab 1</Tab>
</TabList>
<TabPanels>
<TabPanel>
<p>Panel 1</p>
</TabPanel>
</TabPanels>
</Tabs>
</div>
);

expect(getByText("Tab 1")).toHaveAttribute("type", "button");
});

it("allows a custom button type", () => {
const { getByText } = render(
<div>
<Tabs>
<TabList>
<Tab type="submit">Tab 1</Tab>
</TabList>
<TabPanels>
<TabPanel>
<p>Panel 1</p>
</TabPanel>
</TabPanels>
</Tabs>
</div>
);

expect(getByText("Tab 1")).toHaveAttribute("type", "submit");
});
});

describe("a11y", () => {
it("should not have basic a11y issues", async () => {
const { container } = render(
Expand Down
3 changes: 3 additions & 0 deletions packages/tabs/src/index.tsx
Expand Up @@ -455,6 +455,8 @@ export const Tab = forwardRefWithAs<
context: TabsDescendantsContext,
disabled: !!disabled,
});
const htmlType =
Comp === "button" && props.type == null ? "button" : props.type;

const isSelected = index === selectedIndex;

Expand Down Expand Up @@ -507,6 +509,7 @@ export const Tab = forwardRefWithAs<
onClick={onSelect}
onFocus={handleFocus}
onBlur={handleBlur}
type={htmlType}
>
{children}
</Comp>
Expand Down

0 comments on commit e17d904

Please sign in to comment.