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>
),
};As Link
export const AsLink: AnchorStory = {
args: {
as: 'a',
href: '#button-docs',
children: 'Read the docs',
},
};Disabled Link
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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
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 |
icon | Slot<'span'> | No | Icon slot rendered before the label (after it with | |
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. |
disabled | boolean | No | false | Disables the button. Only the intrinsic form controls ( |
disabledFocusable | boolean | No | false | 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 |
as | React.ElementType | No | '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
| Part | Class |
|---|---|
root | wave-button |
icon | wave-button__icon |