ActionIcon
Icon button
Import
Polymorphic
Source
Docs
Package
Usage
Gradient variant
When variant
prop is set to gradient
, you can control gradient with gradient
prop, it accepts an object with from
, to
and deg
properties. If thegradient
prop is not set, ActionIcon
will use theme.defaultGradient
which can be configured on the theme object. gradient
prop is ignored when variant
is not gradient
.
Note that variant="gradient"
supports only linear gradients with two colors. If you need a more complex gradient, then use Styles API to modify ActionIcon
styles.
Size
You can use any valid CSS value in size
prop, it is used to set width
, min-width
, min-height
and height
properties. Note that size
prop does not control child icon size, you need to
set it manually on icon component. When size
is a number, the value is treated as px
units and
converted to rem units.
If you want ActionIcon
to have the same size as Mantine inputs, use size="input-sm"
prop:
Disabled state
To make ActionIcon
disabled set disabled
prop, this will prevent any interactions with the button
and add disabled styles. If you want the button to just look disabled but still be interactive,
set data-disabled
prop instead. Note that disabled styles are the same for all variants.
Disabled state when ActionIcon is link
<a />
element does not support disabled
attribute. To make ActionIcon
disabled when it is
rendered as a link, set data-disabled
attribute instead and prevent default behavior in
onClick
event handler.
Customize disabled styles
To customize disabled styles, it is recommended to use both &:disabled
and &[data-disabled]
selectors:
&:disabled
is used to style the button whendisabled
prop is set and also when the button is disabled by the parent component (for example, whendisabled
prop is set on a<fieldset />
element which containsActionIcon
).&[data-disabled]
is used to style the button when it is not actually disabled but should look like it is (for example,data-disabled
should be used if you need to use Tooltip with disabledActionIcon
or whenActionIcon
is used as a link)
Disabled button with Tooltip
onMouseLeave
event is not triggered when ActionIcon
is disabled, so if you need to use
Tooltip with disabled ActionIcon
you need to set data-disabled
prop on ActionIcon
instead of disabled
. Note that it is also required to change onClick
event handler to
(event) => event.preventDefault()
as ActionIcon
is not actually disabled and will still trigger
onClick
event.
Loading state
When loading
prop is set, ActionIcon
will be disabled and Loader with overlay will be rendered
in the center of the button. Loader color depends on ActionIcon
variant.
Loader props
You can customize Loader with loaderProps
prop, it accepts all props that
Loader component has:
Add custom variants
To add new ActionIcon
variants, use data-variant attribute.
Usually new variants are added on theme, this way they are
available in all ActionIcon
components in your application.
Customize variants colors
You can customize colors for ActionIcon
and other components variants by adding
variantColorResolver to your theme.
autoContrast
ActionIcon
supports autoContrast
prop and theme.autoContrast. If autoContrast
is set either on ActionIcon
or on theme, content color will be adjusted to have sufficient contrast with the value specified in color
prop.
Note that autoContrast
feature works only if you use color
prop to change background color. autoContrast
works only with filled
variant.
Add custom sizes
ActionIcon
sizes are defined by --ai-size-{x}
CSS variables. The easiest way to add new sizes is to
define additional --ai-size-{x}
variables on the root
element:
ActionIcon.Group
Note that you must not wrap child ActionIcon
components with any additional elements:
ActionIcon.GroupSection
Use ActionIcon.GroupSection
component to render sections that are not ActionIcon
inside ActionIcon.Group
:
Polymorphic component
ActionIcon
is a polymorphic component – its default root element is button
, but it can be changed to any other element or component with component
prop:
You can also use components in component
prop, for example, Next.js Link
:
Polymorphic components with TypeScript
Note that polymorphic components props types are different from regular components – they do not extend HTML element props of the default element. For example,
ActionIconProps
does not extendReact.ComponentPropsWithoutRef'<'div'>'
althoughbutton
is the default element.If you want to create a wrapper for a polymorphic component that is not polymorphic (does not support
component
prop), then your component props interface should extend HTML element props, for example:If you want your component to remain polymorphic after wrapping, use
createPolymorphicComponent
function described in this guide.
Get element ref
Accessibility
To make ActionIcon
accessible for screen readers, you need to either set aria-label
or
use VisuallyHidden component: