Morphos
Inputs

Button

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

Interactive example

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".
disabledbooleanDisables the button. Only applied as the native disabled attribute when as is "button"; otherwise exposed via aria-disabled.
hrefstringLink target. Only used when as="a".
onClick(event: MouseEvent) => voidClick handler.
tabIndexnumberTab order override.
classstringCSS class name.
idstringHTML id attribute.
childrenChildrenButton content.
aria-labelstringAccessible label.
aria-pressedbooleanToggle button state.
aria-expandedbooleanDisclosure/popover trigger state.
aria-controlsstringID 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