Icon Button
An Icon Button is a button with only an icon and no visible label text. It is best used for well-known actions with commonly understood icons (e.g. "edit", "delete") and in the direct context of the affected objects (e.g. inside a Tile).
Compared to the Button component, Icon Buttons feature an additional state called highlight. Use it to indicate that a related action or function is active (for instance, when indicating the sorting order in a list).
Example
Usage Rules
Do:
- Use Icon Buttons for contextual actions (e.g. export a chart)
- Add a Tooltip, especially if the icon is not commonly understood (e.g. share)
- Always label the IconButton in your code (You can find more information about this here)
Don’t:
- Mix Icon Buttons of different sizes in the same button group
- Use Icon Buttons for primary actions
- Use the highlight state to simply accentuate an Icon Button
Variants
Disabled
Add the disabled property to visually indicate that an Icon Button is disabled. The user won't be able to click it.
Highlighted
The isHighlighted property indicates that the related to the Button action or function is activated. For instance, in the following example, if an object is set to visible.
Hover
The isHovered property indicates hover state of IconButton.
Icon Badge
The icon badge is a colored dot that acts as a user indication to action. By default it is set to false and can be initiated using the iconBadge
prop. Position is also set by default but can be moved using the iconBadgeOffset
prop, which takes an array of numbers [x,y]
. Sizes and colors follow those set on the IconButton
component.
Kind
The Icon Button comes in six kinds: light
, dark
, 'primary', 'positive', 'warning', 'negative'.
Sizes
The Icon Button comes in two sizes: small
and medium
.
Tooltip
Since an Icon Button doesn’t have a visual label, it is a good idea to add a Tooltip to describe the action of the button. This is especially true if the icon is not commonly understood.
Examples
Working with MouseEvent
Here is an example for using MouseEvents in IconButton
.
If IconButton
has Tooltip
, we should add MouseEvents with an outer div. Because Tooltip
component is using IconButton
MouseEvents to show/hide its content.
Props
Name | Type | Default |
---|---|---|
iconName * Please refer to the full list here: Link | "AddValue" | "AppGrid" | "ArrowCircleLeft" | "ArrowCircleRight" | "ArrowDown" | "ArrowDownLeft" | "A... | — |
type Native HTML attribute: Link |
| "button" |
size Size of the IconButton |
| "medium" |
kind Kind of the IconButton |
| "light" |
isHovered Indicates hover state of component |
| — |
isHighlighted Indicates whether the option represented by the button is active |
| false |
onMouseLeave Native HTML callback: Link |
| — |
onMouseEnter Native HTML callback: Link |
| — |
onFocus Native HTML callback: Link |
| — |
onClick Native HTML callback: Link |
| — |
onBlur Native HTML callback: Link |
| — |
disabled Native HTML attribute: Link |
| — |
aria-label Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
aria-labelledby Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
iconBadge Indicates whether the button has a badge |
| false |
iconBadgeOffset Offset of the badge |
| "[0, 0]" |
isLoading |
| — |
as Support for Link Element |
| — |
to |
| — |
href |
| — |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
ref |
| — |
key |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |