Skip to content

Button

A button allows a user to perform an action, with mouse, touch, and keyboard interactions.

Import

import { Button } from "@cfa/react-core";

Live Editor

Events

The Button is built with the onPress prop, similar to onClick, but supports all user interactions via mouse, keyboard, and touch. The onPressStart, onPressEnd, and onPressChange events are triggered when a user presses, releases, or changes the state of the Button.

These handlers receive a PressEvent with information on type of event and the target.

PressEvent Props

PropertyTypeDescription
type'pressstart' | 'pressend' | 'pressup' | 'press'The type of press event being fired.
pointerTypePointerTypeThe pointer type that triggered the press event.
targetElementThe target element of the press event.
shiftKeybooleanWhether the shift keyboard modifier was held during the press event.
ctrlKeybooleanWhether the ctrl keyboard modifier was held during the press event.
metaKeybooleanWhether the meta keyboard modifier was held during the press event.
altKeybooleanWhether the alt keyboard modifier was held during the press event.
xnumberX position relative to the target.
ynumberY position relative to the target.

PressEvent Methods

MethodDescription
continuePropagation(): voidBy default, press events stop propagation to parent elements. In cases where a handler decides not to handle a specific event, it can allow propagation.

Examples

Color

Variant

Size

Leading & Trailing Icon

To render an icon inside of the Button component, pass the icon as a child along with the label.

LinkButton

The LinkButton component provides the same styling as the Button component but renders as an anchor (<a>) element using React Aria’s Link component underneath. It’s ideal for navigation actions that should visually appear as buttons.

Import

import { LinkButton } from "@cfa/react-core";

Example

LinkButton vs Button

  • Use LinkButton when the action navigates to a new page or URL
  • Use Button when the action performs an operation but stays on the same page
  • LinkButton accepts the same styling props as Button (variant, color, size, fullWidth, isDisabled)
  • LinkButton accepts standard anchor attributes like href, target, etc.

Styling

The LinkButton component supports all the same styling options as the regular Button component (colors, variants, sizes) shown in the examples above. You can add icons, use different variants, and adjust sizes in the same way.

BaseButton

The BaseButton is an unstyled HTML button element that primarily is used as a wrapper to build for building custom button components. It does not include any default styles or behaviors, allowing you to fully customize its appearance.

Import

import { BaseButton } from "@cfa/react-core";

Example

Props

Visit the Documentation Site for the full list of props.

NameTypeDefaultDescription
color"primary" | "secondary"--
fullWidthbooleanfalseRenders the Button in with a fluid width
isDisabledboolean-Whether the button is disabled.
isPendingboolean-Whether the button is in a pending state. This disables press and hover events while retaining the ability to focus, and announces the pending state to screen readers.
refRef<HTMLButtonElement>-Requires React 19
size"sm" | "md" | "lg"lgDetermines the size of the Button
variant"filled" | "outlined" | "destructive" | "text"filledVariant for the button
aria-controlsstring-Identifies the element (or elements) whose contents or presence are controlled by the current element.
aria-currentboolean | "true" | "false" | "page" | "step" | "location" | "date" | "time"-Indicates whether this element represents the current item within a container or set of related elements.
aria-describedbystring-Identifies the element (or elements) that describes the object.
aria-detailsstring-Identifies the element (or elements) that provide a detailed, extended description for the object.
aria-disabledboolean | "true" | "false"-Indicates whether the element is disabled to users of assistive technology.
aria-expandedboolean | "true" | "false"-Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-haspopupboolean | "true" | "false" | "menu" | "listbox" | "tree" | "grid" | "dialog"-Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-labelstring-Defines a string value that labels the current element.
aria-labelledbystring-Identifies the element (or elements) that labels the current element.
aria-pressedboolean | "true" | "false" | "mixed"-Indicates the current "pressed" state of toggle buttons.
autoFocusboolean-Whether the element should receive focus on render.
childrenChildrenOrFunction<ButtonRenderProps>-The children of the component. A function may be provided to alter the children based on component state.
classNameClassNameOrFunction<ButtonRenderProps>'react-aria-Button'The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.
dirstring--
excludeFromTabOrderboolean-Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
formstring-The `<form>` element to associate the button with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#form).
formActionstring | ((formData: FormData) => void | Promise<void>)-The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner.
formEncTypestring-Indicates how to encode the form data that is submitted.
formMethodstring-Indicates the HTTP method used to submit the form.
formNoValidateboolean-Indicates that the form is not to be validated when it is submitted.
formTargetstring-Overrides the target attribute of the button's form owner.
hiddenboolean--
idstring-The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
inertboolean--
langstring--
namestring-Submitted as a pair with the button's value as part of the form data.
onAnimationEndAnimationEventHandler<HTMLButtonElement>--
onAnimationEndCaptureAnimationEventHandler<HTMLButtonElement>--
onAnimationIterationAnimationEventHandler<HTMLButtonElement>--
onAnimationIterationCaptureAnimationEventHandler<HTMLButtonElement>--
onAnimationStartAnimationEventHandler<HTMLButtonElement>--
onAnimationStartCaptureAnimationEventHandler<HTMLButtonElement>--
onAuxClickMouseEventHandler<HTMLButtonElement>--
onAuxClickCaptureMouseEventHandler<HTMLButtonElement>--
onBlur(e: FocusEvent<Element, Element>) => void-Handler that is called when the element loses focus.
onClickCaptureMouseEventHandler<HTMLButtonElement>--
onContextMenuMouseEventHandler<HTMLButtonElement>--
onContextMenuCaptureMouseEventHandler<HTMLButtonElement>--
onDoubleClickMouseEventHandler<HTMLButtonElement>--
onDoubleClickCaptureMouseEventHandler<HTMLButtonElement>--
onFocus(e: FocusEvent<Element, Element>) => void-Handler that is called when the element receives focus.
onFocusChange(isFocused: boolean) => void-Handler that is called when the element's focus status changes.
onGotPointerCapturePointerEventHandler<HTMLButtonElement>--
onGotPointerCaptureCapturePointerEventHandler<HTMLButtonElement>--
onHoverChange(isHovering: boolean) => void-Handler that is called when the hover state changes.
onHoverEnd(e: HoverEvent) => void-Handler that is called when a hover interaction ends.
onHoverStart(e: HoverEvent) => void-Handler that is called when a hover interaction starts.
onKeyDown(e: KeyboardEvent) => void-Handler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => void-Handler that is called when a key is released.
onLostPointerCapturePointerEventHandler<HTMLButtonElement>--
onLostPointerCaptureCapturePointerEventHandler<HTMLButtonElement>--
onMouseDownMouseEventHandler<HTMLButtonElement>--
onMouseDownCaptureMouseEventHandler<HTMLButtonElement>--
onMouseEnterMouseEventHandler<HTMLButtonElement>--
onMouseLeaveMouseEventHandler<HTMLButtonElement>--
onMouseMoveMouseEventHandler<HTMLButtonElement>--
onMouseMoveCaptureMouseEventHandler<HTMLButtonElement>--
onMouseOutMouseEventHandler<HTMLButtonElement>--
onMouseOutCaptureMouseEventHandler<HTMLButtonElement>--
onMouseOverMouseEventHandler<HTMLButtonElement>--
onMouseOverCaptureMouseEventHandler<HTMLButtonElement>--
onMouseUpMouseEventHandler<HTMLButtonElement>--
onMouseUpCaptureMouseEventHandler<HTMLButtonElement>--
onPointerCancelPointerEventHandler<HTMLButtonElement>--
onPointerCancelCapturePointerEventHandler<HTMLButtonElement>--
onPointerDownPointerEventHandler<HTMLButtonElement>--
onPointerDownCapturePointerEventHandler<HTMLButtonElement>--
onPointerEnterPointerEventHandler<HTMLButtonElement>--
onPointerLeavePointerEventHandler<HTMLButtonElement>--
onPointerMovePointerEventHandler<HTMLButtonElement>--
onPointerMoveCapturePointerEventHandler<HTMLButtonElement>--
onPointerOutPointerEventHandler<HTMLButtonElement>--
onPointerOutCapturePointerEventHandler<HTMLButtonElement>--
onPointerOverPointerEventHandler<HTMLButtonElement>--
onPointerOverCapturePointerEventHandler<HTMLButtonElement>--
onPointerUpPointerEventHandler<HTMLButtonElement>--
onPointerUpCapturePointerEventHandler<HTMLButtonElement>--
onPress(e: PressEvent) => void-Handler that is called when the press is released over the target.
onPressChange(isPressed: boolean) => void-Handler that is called when the press state changes.
onPressEnd(e: PressEvent) => void-Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressStart(e: PressEvent) => void-Handler that is called when a press interaction starts.
onPressUp(e: PressEvent) => void-Handler that is called when a press is released over the target, regardless of whether it started on the target or not.
onScrollUIEventHandler<HTMLButtonElement>--
onScrollCaptureUIEventHandler<HTMLButtonElement>--
onTouchCancelTouchEventHandler<HTMLButtonElement>--
onTouchCancelCaptureTouchEventHandler<HTMLButtonElement>--
onTouchEndTouchEventHandler<HTMLButtonElement>--
onTouchEndCaptureTouchEventHandler<HTMLButtonElement>--
onTouchMoveTouchEventHandler<HTMLButtonElement>--
onTouchMoveCaptureTouchEventHandler<HTMLButtonElement>--
onTouchStartTouchEventHandler<HTMLButtonElement>--
onTouchStartCaptureTouchEventHandler<HTMLButtonElement>--
onTransitionCancelTransitionEventHandler<HTMLButtonElement>--
onTransitionCancelCaptureTransitionEventHandler<HTMLButtonElement>--
onTransitionEndTransitionEventHandler<HTMLButtonElement>--
onTransitionEndCaptureTransitionEventHandler<HTMLButtonElement>--
onTransitionRunTransitionEventHandler<HTMLButtonElement>--
onTransitionRunCaptureTransitionEventHandler<HTMLButtonElement>--
onTransitionStartTransitionEventHandler<HTMLButtonElement>--
onTransitionStartCaptureTransitionEventHandler<HTMLButtonElement>--
onWheelWheelEventHandler<HTMLButtonElement>--
onWheelCaptureWheelEventHandler<HTMLButtonElement>--
preventFocusOnPressboolean-Whether to prevent focus from moving to the button when pressing it. Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control.
renderDOMRenderFunction<"button", ButtonRenderProps>-Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements: * You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`). * Only a single root DOM element can be rendered (no fragments). * You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
slotstring-A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent.
styleStyleOrFunction<ButtonRenderProps>-The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state.
translate"yes" | "no"--
type"button" | "submit" | "reset"'button'The behavior of the button when used in an HTML form.
valuestring-The value associated with the button's name when it's submitted with the form data.