Button
A button that presses with a mouse, a touch, a pen, Enter, Space, or a screen reader. Each way calls the same handlers.
Pressed 0 times.
<script>
import { $signal } from 'brumate/signals';
import Button from '@brumate/ui/Button.brm';
let presses = $signal(0);
let last = $signal('');
</script>
<Button
class="ui-button"
onPress=((event) => {
presses++;
last = event.pointerType;
})
>Press me</Button>
<Button class="ui-button" isPending>Saving</Button>
<Button class="ui-button" isDisabled>Disabled</Button>
<p>Pressed {presses === 1 ? 'once' : `${presses} times`}{last ? `, last with ${last}` : ''}.</p>
onPressruns when a press ends on the button.onPressStart,onPressEnd,onPressUpandonPressChangefollow each step, and their event haspointerType:mouse,touch,pen,keyboardorvirtual.onHoverStart,onHoverEndandonHoverChangefollow a mouse or a pen. A touch never hovers.isDisabledsetsdisabledon the button.isPendingkeeps its focus and presses nothing, such as while a form sends.typeisbuttonby default, so a button in a form does not send it. Usetype="submit"for one that does.asrenders another element, such asas="a", withrole="button"and a place in the order of Tab.astakes the name of an element or a component, and the other props are those of the target, soas="a"takeshref, and a prop that the target does not take is a type error.ButtonPropsis the props type. See Props types.- A press that leaves the button ends without
onPress, and starts again when the pointer comes back. Space never scrolls the page.
Attributes
| Attribute | When |
|---|---|
data-pressed |
A pointer or a key holds it down. |
data-hovered |
A mouse or a pen is over it. |
data-focused |
It has focus. |
data-focus-visible |
Its focus shows as a ring. |
data-disabled |
It is disabled. |
data-pending |
It is pending. |
In other parts
Many parts give the Button inside them its role, its state and its handlers through a context, such as the trigger of a Disclosure, of a DialogTrigger or of a TooltipTrigger. slot picks the button that a part means, such as slot="close" in a Dialog. The handlers of the part run first, then yours.