Skip to content

CompoundButton

CompoundButton

A button with a main label and a secondary line of text below it, and an optional icon beside them. Built on Button: same appearances, sizes, token colors, type="button" default, disabled/disabledFocusable and polymorphic as behaviour (as="a" renders a link; a non-interactive as gets role="button", a tab stop and Enter/Space activation; disabled becomes aria-disabled on non-form-control elements).

- The text lines sit in a column wrapper (span[data-wave-compound-content]); the icon renders before or after it (iconPosition).
- secondaryText and contentContainer are slots: content or a slot object (as, className, attributes, a render function) for the second line, a slot object for the column around the text, both merged over slotProps.
- shape rounds the corners as on Button.
- With only an icon (no label and no secondaryText) it is an icon-only Button: square, with the icon-only sizing and name check.

Examples

Default

export const Default: Story = {};

Without Secondary Text

export const WithoutSecondaryText: Story = {
  args: {
    children: 'Compound button',
    secondaryText: undefined,
  },
};

Primary

export const Primary: Story = {
  args: {
    appearance: 'primary',
    children: 'Create account',
    secondaryText: 'Free for 30 days',
  },
};

With Icon

export const WithIcon: Story = {
  args: {
    children: 'Schedule meeting',
    secondaryText: 'Next Monday at 9:00',
    icon: <CalendarIcon />,
  },
};

Icon After

export const IconAfter: Story = {
  args: {
    children: 'Schedule meeting',
    secondaryText: 'Next Monday at 9:00',
    icon: <CalendarIcon />,
    iconPosition: 'after',
  },
};

Disabled

export const Disabled: Story = {
  args: {
    disabled: true,
  },
};
export const AsLink: AnchorStory = {
  args: {
    as: 'a',
    href: '#compound-button-docs',
    children: 'Read the guide',
    secondaryText: 'Five-minute introduction',
  },
};

Sizes

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

Shapes

export const Shapes: Story = {
  argTypes: {
    shape: { control: false },
  },
  render: (args) => (
    <div className="flex items-start gap-2">
      <CompoundButton {...args} shape="rounded" secondaryText="rounded">
        Rounded
      </CompoundButton>
      <CompoundButton {...args} shape="circular" secondaryText="circular">
        Circular
      </CompoundButton>
      <CompoundButton {...args} shape="square" secondaryText="square">
        Square
      </CompoundButton>
    </div>
  ),
};

Slot Objects

export const SlotObjects: Story = {
  args: {
    secondaryText: { children: 'Free for 30 days', className: 'italic' },
    contentContainer: { className: 'gap-0.5', 'data-testid': 'column' },
    children: 'Create account',
  },
};

Props

NameTypeRequiredDefaultDescription
secondaryTextSlot<'span'>No

Secondary descriptive text displayed below the main label (part of the accessible name), Fluent's secondaryContent slot: any content (its text is the second line), or a slot object ({ children, className, as, ...attributes }) for the element of that line. Content that renders nothing ('', [], <></>) renders no second line; a slot object always renders one. The slot object's attributes merge over slotProps.secondaryText (its classes, handlers and refs join); the attributes the component locks (slotProps.secondaryText) stay locked.

contentContainerSlotObject<'span'>No

The element around the two lines of text, Fluent's contentContainer slot, as a slot object: as renders another element, className, style, ref, handlers and attributes are merged over slotProps.contentContainer, and a render function as children ((Component, props) => …) renders the column, with the two lines as props.children. Other children of the object are ignored (the lines are its content). The attribute the component locks (data-wave-compound-content) stays locked, and a click handler is not called while the button is disabled or disabledFocusable. Without any text (an icon-only button) the column does not render.

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

Visual style variant.

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

Size affecting padding and font size.

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

Corner shape, as on Button.

disabledbooleanNofalse

Disables the button. As with Button: a native disabled attribute for form controls (the default button); every other as gets aria-disabled="true" and tabIndex={-1}, its activation is prevented and an <a> drops its href.

disabledFocusablebooleanNofalse

Marks the button unavailable but keeps it focusable and in the tab order (for a Tooltip that explains why, or a toolbar). 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, and your onClick is not called. Wins over disabled when both are set. In a Toolbar it stays in the arrow-key order.

iconSlot<'span'>No

Icon shown beside the two lines of text, in a 40px box (32px at small, 24px at extra-small) whose SVG fills it. Decorative (aria-hidden). A CompoundButton with only an icon (no label, no secondaryText) is an icon-only button: it looks and is checked like an icon-only Button and needs aria-label, aria-labelledby or title.

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

Where the icon renders: before the text column (the inline start) or after it (the inline end). Follows the writing direction through DOM order. Has no effect without an icon or on an icon-only button.

slotProps{ contentContainer?: SlotPart<'span'>; primaryText?: SlotPart<'span'>; secondaryText?: SlotPart<'span'> }No

Props for the elements the CompoundButton draws inside the button, by part, merged into each part's own (Fluent UI's contentContainer and secondaryContent slot props; the button itself and its icon are the Button's, reached through the CompoundButton's own props): your classes after the part's (yours win a conflict), your styles over its styles, your handlers and attributes added, your ref attached. Every attribute the CompoundButton sets on a part is locked. A part takes no children (the label and secondaryText are its content). No part carries a handler of the button: a click on a part is a click on the button, after yours, so preventDefault() in yours cancels the button's native activation (the submission of a submit button), while the button's own onClick still runs. While the button is disabled or disabledFocusable, your onClick on a part is not called, as the button's own is not. A CompoundButton with only an icon draws no part and ignores them.

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).

Parts

  • contentContainer
  • primaryText
  • secondaryText

Stable class names

PartClass
rootwave-compound-button
iconwave-compound-button__icon
contentContainerwave-compound-button__content-container
primaryTextwave-compound-button__primary-text
secondaryTextwave-compound-button__secondary-text