Morphos
Inputs

Button

A headless button primitive supporting polymorphism via the `as` prop.

Interactive example

Open in Storybook

Installation

npm install @morphos/inputs
pnpm add @morphos/inputs
yarn add @morphos/inputs
bun add @morphos/inputs

Import

import { Button } from '@morphos/inputs'

Usage

@Component()
class MyComponent extends StatefulComponent {
  render() {
    return (
      <Button onClick={() => console.log('clicked')}>
        Click me
      </Button>
    )
  }
}

Polymorphism

Render as a different element using the as prop:

<Button as="a" href="/dashboard">Go to dashboard</Button>
<Button as="span" role="button" tabIndex={0}>Span button</Button>

Props

PropTypeDefaultDescription
as"button" | "a" | "span" | "div""button"Renders as a different HTML element.
type"button" | "submit" | "reset""button"Native button type. Only applied when as is "button".
disabledboolean—Disables the button. Only applied as the native disabled attribute when as is "button"; otherwise exposed via aria-disabled.
hrefstring—Link target. Only used when as="a".
onClick(event: MouseEvent) => void—Click handler.
tabIndexnumber—Tab order override.
classstring—CSS class name.
idstring—HTML id attribute.
childrenChildren—Button content.
aria-labelstring—Accessible label.
aria-pressedboolean—Toggle button state.
aria-expandedboolean—Disclosure/popover trigger state.
aria-controlsstring—ID of the element controlled by this button.
aria-haspopupboolean | "menu" | "listbox" | "dialog"—Indicates the kind of popup triggered by this button.

data-* attributes

AttributeElementWhen present
data-disabledRootdisabled is true

Styling example

button[data-disabled],
a[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

When as is not "button", the disabled attribute is replaced by aria-disabled="true", since non-button elements do not support the native disabled attribute.

On this page