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

feat(Button): add as prop to IconButton inside of the Button component #12900

Merged
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
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://avatars.githubusercontent.com/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://avatars.githubusercontent.com/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://avatars.githubusercontent.com/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://avatars.githubusercontent.com/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');
});
});
});