ActionIcon

Icon button

Import

Usage

Color
Size
Radius
import { ActionIcon } from '@mantine/core';
import { IconAdjustments } from '@tabler/icons-react';

function Demo() {
  return (
    <ActionIcon variant="filled" aria-label="Settings">
      <IconAdjustments style={{ width: '70%', height: '70%' }} stroke={1.5} />
    </ActionIcon>
  );
}

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.

Gradient from
Gradient to
Gradient degree
import { ActionIcon } from '@mantine/core';
import { IconHeart } from '@tabler/icons-react';

function Demo() {
  return (
    <ActionIcon
      variant="gradient"
      size="xl"
      aria-label="Gradient action icon"
      gradient={{ from: 'blue', to: 'cyan', deg: 90 }}
    >
      <IconHeart />
    </ActionIcon>
  );
}

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.

import { ActionIcon, rem } from '@mantine/core';
import { IconHeart } from '@tabler/icons-react';

function Demo() {
  return (
    <ActionIcon size={42} variant="default" aria-label="ActionIcon with size as a number">
      <IconHeart style={{ width: rem(24), height: rem(24) }} />
    </ActionIcon>
  );
}

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.

import { ActionIcon, Group } from '@mantine/core';
import { IconHeart } from '@tabler/icons-react';

function Demo() {
  return (
    <Group justify="center">
      <ActionIcon size="xl" disabled aria-label="Disabled and not interactive">
        <IconHeart />
      </ActionIcon>

      <ActionIcon size="xl" data-disabled aria-label="Has disabled styles but still interactive">
        <IconHeart />
      </ActionIcon>
    </Group>
  );
}

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.

import { ActionIcon } from '@mantine/core';
import { IconExternalLink } from '@tabler/icons-react';

function Demo() {
  return (
    <ActionIcon
      component="a"
      href="https://mantine.dev"
      data-disabled
      size="xl"
      aria-label="Open in a new tab"
      onClick={(event) => event.preventDefault()}
    >
      <IconExternalLink />
    </ActionIcon>
  );
}

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 when disabled prop is set and also when the button is disabled by the parent component (for example, when 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 disabled ActionIcon or when ActionIcon is used as a link)
.button {
  &:disabled,
  &[data-disabled] {
    border-color: light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4));
    background-color: transparent;
  }
}

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.

import { ActionIcon, Tooltip } from '@mantine/core';
import { IconHeart } from '@tabler/icons-react';

function Demo() {
  return (
    <Tooltip label="Tooltip for disabled button">
      <ActionIcon size="xl" data-disabled onClick={(event) => event.preventDefault()}>
        <IconHeart />
      </ActionIcon>
    </Tooltip>
  );
}

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.

import { ActionIcon, Group } from '@mantine/core';

function Demo() {
  return (
    <Group justify="center">
      <ActionIcon loading aria-label="Filled loading" />
      <ActionIcon variant="light" loading aria-label="Light loading" />
      <ActionIcon variant="outline" loading aria-label="Outline loading" />
    </Group>
  );
}

Loader props

You can customize Loader with loaderProps prop, it accepts all props that Loader component has:

import { ActionIcon } from '@mantine/core';

function Demo() {
  return <ActionIcon size="xl" loading loaderProps={{ type: 'dots' }} />;
}

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.

import { Group, ActionIcon, MantineProvider, createTheme } from '@mantine/core';
import { IconHeart } from '@tabler/icons-react';
import classes from './Demo.module.css';

const theme = createTheme({
  components: {
    ActionIcon: ActionIcon.extend({
      classNames: classes,
    }),
  },
});

function Demo() {
  return (
    <MantineProvider theme={theme}>
      <Group justify="center">
        <ActionIcon size="xl" variant="danger" aria-label="Danger variant">
          <IconHeart />
        </ActionIcon>
        <ActionIcon size="xl" variant="primary" aria-label="Primary variant">
          <IconHeart />
        </ActionIcon>
      </Group>
    </MantineProvider>
  );
}

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:

.root {
  --ai-size-xxs: rem(16px);
  --ai-size-xxl: rem(50px);
}

ActionIcon.Group

Orientation
import { ActionIcon, rem } from '@mantine/core';
import { IconPhoto, IconSettings, IconHeart } from '@tabler/icons-react';

function Demo() {
  return (
    <ActionIcon.Group>
      <ActionIcon variant="default" size="lg" aria-label="Gallery">
        <IconPhoto style={{ width: rem(20) }} stroke={1.5} />
      </ActionIcon>

      <ActionIcon variant="default" size="lg" aria-label="Settings">
        <IconSettings style={{ width: rem(20) }} stroke={1.5} />
      </ActionIcon>

      <ActionIcon variant="default" size="lg" aria-label="Likes">
        <IconHeart style={{ width: rem(20) }} stroke={1.5} />
      </ActionIcon>
    </ActionIcon.Group>
  );
}

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>
  );
}

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:

import { ActionIcon } from '@mantine/core';

function Demo() {
  return <ActionIcon component="a" />;
}

You can also use components in component prop, for example, Next.js Link:

import Link from 'next/link';
import { ActionIcon } from '@mantine/core';

function Demo() {
  return <ActionIcon component={Link} href="/" />;
}

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 extend React.ComponentPropsWithoutRef'<'div'>' although button 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:

import type { ActionIconProps, ElementProps } from '@mantine/core';

interface MyActionIconProps extends ActionIconProps,
  ElementProps<'a', keyof ActionIconProps> {}

If you want your component to remain polymorphic after wrapping, use createPolymorphicComponent function described in this guide.

Get element ref

import { useRef } from 'react';
import { ActionIcon } from '@mantine/core';

function Demo() {
  const ref = useRef<HTMLButtonElement>(null);
  return <ActionIcon ref={ref} />;
}

Accessibility

To make ActionIcon accessible for screen readers, you need to either set aria-label or use VisuallyHidden component:

import { ActionIcon, VisuallyHidden } from '@mantine/core';
import { IconHeart } from '@tabler/icons-react';

function Demo() {
  return (
    <>
      <ActionIcon aria-label="Like post">
        <IconHeart />
      </ActionIcon>

      <ActionIcon>
        <VisuallyHidden>Like post</VisuallyHidden>
        <IconHeart />
      </ActionIcon>
    </>
  );
}