apps/mantine.dev/src/pages/core/action-icon.mdx
import { ActionIconDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.ActionIcon);
You can use any valid CSS value in the size prop, which is used to set the width, min-width, min-height and height
properties. Note that the size prop does not control the child icon size – you need to
set it manually on the 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 the size="input-sm" prop:
To make ActionIcon disabled, set the 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 the data-disabled prop instead. Note that disabled styles are the same for all variants.
The <a /> element does not support the disabled attribute. To make ActionIcon disabled when it is
rendered as a link, set the data-disabled attribute instead and prevent default behavior in the
onClick event handler.
To customize disabled styles, it is recommended to use both &:disabled and &[data-disabled]
selectors:
&:disabled is used to style the button when the disabled prop is set and
also when the button is disabled by the parent component (for example, when the disabled prop is set on a
<fieldset /> element which contains ActionIcon).&[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 a disabled ActionIcon
or when ActionIcon is used as a link)The onMouseLeave event is not triggered when ActionIcon is disabled, so if you need to use
Tooltip with a disabled ActionIcon, you need to set the data-disabled prop on ActionIcon
instead of disabled. Note that it is also required to change the onClick event handler to
(event) => event.preventDefault() as ActionIcon is not actually disabled and will still trigger
the onClick event.
When the loading prop is set, ActionIcon will be disabled and a Loader with overlay will be rendered
in the center of the button. The Loader color depends on the ActionIcon variant.
You can customize the Loader with the loaderProps prop, which accepts all props that the
Loader component has:
To add new ActionIcon variants, use the data-variant attribute.
Usually new variants are added to the theme. This way they are
available in all ActionIcon components in your application.
You can customize colors for ActionIcon and other components variants by adding
variantColorResolver to your theme.
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:
Note that you must not wrap child ActionIcon components with any additional elements:
import { ActionIcon } from '@mantine/core';
// Will not work correctly
function Demo() {
return (
<ActionIcon.Group>
<div>
<ActionIcon>This will not work</ActionIcon>
</div>
<ActionIcon>ActionIcons will have incorrect borders</ActionIcon>
</ActionIcon.Group>
);
}
Use the ActionIcon.GroupSection component to render sections that are not ActionIcon inside ActionIcon.Group:
<Polymorphic defaultElement="button" changeToElement="a" component="ActionIcon" withNext />
<GetElementRef component="ActionIcon" refType="button" />To make ActionIcon accessible for screen readers, you need to either set aria-label or
use the VisuallyHidden component:
import { HeartIcon } from '@phosphor-icons/react';
import { ActionIcon, VisuallyHidden } from '@mantine/core';
function Demo() {
return (
<>
<ActionIcon aria-label="Like post">
<HeartIcon />
</ActionIcon>
<ActionIcon>
<VisuallyHidden>Like post</VisuallyHidden>
<HeartIcon />
</ActionIcon>
</>
);
}