Skip to content

Button

Button

A button with Fluent appearances and sizes.

- Renders a <button type="button"> by default (pass type="submit" to submit a form).
- as renders another element or component with correctly typed props (<Button as="a" href="/docs">, <Button as={RouterLink} to="/">).
- Non-button elements keep button semantics: an element that is not interactive by itself (as="div", as="span") and an as="a" without href get role="button", a tab stop and Enter/Space activation (an <a> with any href, '' included, stays a link), and disabled becomes aria-disabled + tabIndex={-1} with clicks and keys prevented.
- A custom as component receives neither the type="button" default nor disabled (see disabled), even when it renders a native <button>: pass type yourself inside a form.
- The icon slot is decorative (aria-hidden); give icon-only buttons an aria-label.
- disabledFocusable keeps an unavailable button focusable (a Tooltip can explain why, a toolbar keeps it in its arrow-key order) and blocks its activation.
- A consumer aria-disabled="true" shows the disabled look and suppresses hover and pressed colors, but the button stays focusable and its handlers still run: guard them yourself, or use disabledFocusable, which does both.
- Colors are theme tokens; hover and pressed styles never apply while disabled.
- Hover and pressed colors are gated (not-disabled:not-aria-disabled:hover:), which gives them a higher CSS specificity than a bare hover: class. To override them in className, use the same prefix (not-disabled:not-aria-disabled:hover:bg-error, which replaces the built-in class) or the important modifier (hover:bg-error!).

Examples

Default

export const Default: Story = {
  args: {
    children: 'Button',
  },
};

Primary

export const Primary: Story = {
  args: {
    appearance: 'primary',
    children: 'Primary',
  },
};

Outline

export const Outline: Story = {
  args: {
    appearance: 'outline',
    children: 'Outline',
  },
};

Subtle

export const Subtle: Story = {
  args: {
    appearance: 'subtle',
    children: 'Subtle',
  },
};

Transparent

export const Transparent: Story = {
  args: {
    appearance: 'transparent',
    children: 'Transparent',
  },
};

With Icon

export const WithIcon: Story = {
  args: {
    children: 'Attach file',
    icon: <PaperclipIcon />,
  },
};

Icon After

export const IconAfter: Story = {
  args: {
    children: 'Open in new window',
    icon: <OpenIcon />,
    iconPosition: 'after',
  },
};

Icon Only

export const IconOnly: Story = {
  args: {
    icon: <PaperclipIcon />,
    'aria-label': 'Attach file',
  },
};

Sizes

export const Sizes: Story = {
  argTypes: {
    size: { control: false },
  },
  render: (args) => (
    <div className="flex items-center gap-2">
      {sizes.map((size) => (
        <Button key={size} {...args} size={size}>
          {size}
        </Button>
      ))}
    </div>
  ),
};

Disabled

export const Disabled: Story = {
  args: {
    children: 'Disabled',
    disabled: true,
  },
};

Disabled Focusable

export const DisabledFocusable: Story = {
  args: {
    children: 'Save',
    disabledFocusable: true,
  },
  render: (args) => (
    <Tooltip content="Make a change before you save">
      <Button {...args} />
    </Tooltip>
  ),
};
export const AsLink: AnchorStory = {
  args: {
    as: 'a',
    href: '#button-docs',
    children: 'Read the docs',
  },
};
export const DisabledLink: AnchorStory = {
  args: {
    as: 'a',
    href: '#button-docs',
    children: 'Read the docs',
    disabled: true,
  },
};

Shapes

export const Shapes: Story = {
  argTypes: {
    shape: { control: false },
  },
  render: (args) => (
    <div className="flex items-center gap-2">
      {shapes.map((shape) => (
        <Button key={shape} {...args} shape={shape}>
          {shape}
        </Button>
      ))}
      {shapes.map((shape) => (
        <Button
          key={`${shape}-icon`}
          {...args}
          shape={shape}
          icon={<PaperclipIcon />}
          aria-label={`Attach (${shape})`}
        />
      ))}
    </div>
  ),
};

Props

NameTypeRequiredDefaultDescription
appearance'primary' | 'outline' | 'subtle' | 'transparent'No'outline'

Visual style variant.

size'extra-small' | 'small' | 'medium' | 'large' | 'extra-large'No'medium'

Size affecting height, padding and font size.

shape'circular' | 'square' | 'rounded'No'rounded'

Corner shape (Fluent's shape): rounded is the default corner radius, circular a pill (a circle on an icon-only button) and square has no rounding. Renders data-shape while it is set. In a SplitButton, the shape of both halves is the SplitButton's.

iconSlot<'span'>No

Icon slot rendered before the label (after it with iconPosition="after"). Decorative: it renders with aria-hidden="true" (a slot object can override it). An icon-only button needs aria-label, aria-labelledby or title.

iconPosition'before' | 'after'No'before'

Where the icon renders: before the label (the inline start) or after it (the inline end, e.g. an "open in new window" glyph). Follows the writing direction through DOM order. Has no effect on an icon-only button.

disabledbooleanNofalse

Disables the button. Only the intrinsic form controls (button, the default, and input, select, textarea) get the native disabled attribute. Every other as — a, div, span and **any custom component**, including router links and styled or motion components that render a native <button> — does not receive disabled: it gets aria-disabled="true" and tabIndex={-1} instead (neither can be overridden), its clicks and Enter/Space are prevented (a click does not reach ancestor onClick handlers either, as with a native disabled button), and an <a> drops its href (it keeps role="link" when it had one, role="button" otherwise). Such an element leaves the tab order but, like any tabIndex={-1} element, can still take focus from a mouse click, and a component's own :disabled styling does not apply. Every disabled Button also renders data-disabled.

disabledFocusablebooleanNofalse

Marks the button unavailable but keeps it focusable and in the tab order: for toolbar items, a button that disables itself when activated, or a disabled button that needs a Tooltip. Renders aria-disabled="true", data-disabled and data-disabled-focusable instead of the native disabled attribute. Clicks, Enter, Space and implicit form submission are prevented; your onClick is not called and the click does not reach ancestor click handlers. Hover and pressed colors are off. Wins over disabled when both are set. In a Toolbar it stays in the arrow-key order.

asReact.ElementTypeNo'button'

Render as a different element or component (its props are type-checked).

Any other prop is passed to the element it renders (HTMLButtonElement).

Stable class names

PartClass
rootwave-button
iconwave-button__icon