React Aria

3.48.0 · active · verified Sun Apr 19

React Aria is a collection of unstyled, accessible UI primitives and hooks for building robust and inclusive user interfaces in React. Unlike traditional component libraries that provide pre-styled components, React Aria offers a foundational layer of accessibility, interaction logic, and internationalization, allowing developers complete control over visual styling and DOM structure. The current stable version is 3.48.0, with new features and improvements released frequently, typically on a monthly or bi-monthly cadence. Its core differentiator lies in its 'headless' nature, focusing purely on standardized, accessible behavior by leveraging WAI-ARIA practices, making it an ideal choice for design systems that require highly customizable yet fully accessible components without opinionated styling.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a custom accessible button using `useButton` from React Aria, applying the necessary props and a ref to a native HTML button element. It also shows `mergeProps` for combining properties.

import React from 'react';
import { useButton } from 'react-aria';
import { mergeProps } from 'react-aria';

interface MyButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  onPress?: () => void;
}

function MyButton(props: MyButtonProps) {
  let ref = React.useRef<HTMLButtonElement>(null);
  let { buttonProps, isPressed } = useButton(props, ref);

  return (
    <button
      {...mergeProps(buttonProps, props)}
      ref={ref}
      style={{
        backgroundColor: isPressed ? 'darkblue' : 'blue',
        color: 'white',
        padding: '10px 20px',
        border: 'none',
        borderRadius: '5px',
        cursor: 'pointer'
      }}
    >
      {props.children}
    </button>
  );
}

// Example usage in a component
export function App() {
  const handlePress = () => {
    console.log('Button pressed!');
    alert('Hello from React Aria Button!');
  };

  return (
    <div>
      <h1>React Aria Quickstart</h1>
      <MyButton onPress={handlePress}>Click Me</MyButton>
    </div>
  );
}

view raw JSON →