IconButton composes the Button component except that it renders only an icon.
Import
import { IconButton } from '@contentful/f36-components';// orimport { IconButton } from '@contentful/f36-button';
Examples
Sizes and Variations
You need to pass an Icon component you want to render to the icon prop, you may also provide variant and size to the icon.
As toolbar actions
In toolbars, action bars, and in all other space restricted containers we suggest using IconButton instead of Button component.
For these cases, it would be also beneficial to use Tooltip as a wrapper of IconButton to help users with understanding the button's purpose.
Props (API reference)
- Namearia-label(required)DescriptionAria label is required when using icon only string
- Nameicon(required)DescriptionExpects any of the icon components ReactElement<any, string | JSXElementConstructor<any>>
- NameasDescriptionThe element used for the root node. HTML Tag or React Component (e.g. div, span, etc)
- NamechildrenReactNode
- NameclassNameDescriptionCSS class to be appended to the root element string
- NameisActiveDescriptionApplies active styles falsetrue
- NameisDisabledDescriptionDisabled interaction and applies disabled styles falsetrue
- NameisFullWidthDescriptionForces button to take 100% of the container falsetrue
- NameisLoadingDescriptionAdds loading indicator icon and disables interactions falsetrue
- NamesizeDescriptionDetermines size variation of Button component "small""medium""large"
- NametestIdDescriptionA [data-test-id] attribute used for testing purposes string
- NamevariantDescriptionDetermines style variation of Button component "negative""positive""primary""secondary""transparent"
Accessibility
We enforce aria-label property for IconButton component to ensure that these buttons are fully accessible for screen readers.