React Aria Components

1.17.0 · active · verified Sun Apr 19

React Aria Components (RAC) provides a comprehensive set of headless, accessible, and styleable UI components built directly on the highly acclaimed React Aria hooks library. It simplifies the creation of rich user interfaces by offering ready-to-use component primitives for common UI patterns like buttons, text fields, tables, combo boxes, and trees, while leaving the visual styling entirely up to the developer. The library is currently on version 1.17.0 and maintains a frequent release cadence, typically monthly or bi-monthly, introducing new features, improvements, and accessibility enhancements. Its core differentiators are its strong emphasis on WAI-ARIA authoring practices, full type safety with TypeScript, and its 'bring your own styling' approach, making it highly adaptable to any design system. This allows developers to build custom-styled components without compromising on accessibility or complex interaction logic, fostering a robust foundation for building inclusive web applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the composition of a simple accessible form using `TextField` (with `Label` and `Input`), a `Button`, and an accessible modal dialog (`DialogTrigger`, `Modal`, `Dialog`) for submission confirmation. It highlights the headless nature of RAC by applying basic Tailwind-like class names for visual styling.

import { Button, Dialog, DialogTrigger, Heading, Modal, Text, TextField, Label, Input } from 'react-aria-components';
import React from 'react';

function MyForm() {
  return (
    <form className="flex flex-col gap-4 p-4 border border-gray-200 rounded-lg shadow-md max-w-sm mx-auto my-8">
      <Heading level={2} className="text-2xl font-semibold text-gray-800">Contact Us</Heading>
      <TextField className="flex flex-col gap-1">
        <Label className="font-medium text-gray-700">Your Name</Label>
        <Input type="text" placeholder="John Doe" className="border border-gray-300 rounded-md p-2 focus:ring-2 focus:ring-blue-400 focus:border-transparent transition-colors duration-150" />
      </TextField>
      <TextField className="flex flex-col gap-1">
        <Label className="font-medium text-gray-700">Email Address</Label>
        <Input type="email" placeholder="john.doe@example.com" className="border border-gray-300 rounded-md p-2 focus:ring-2 focus:ring-blue-400 focus:border-transparent transition-colors duration-150" />
      </TextField>
      <DialogTrigger>
        <Button className="bg-blue-600 text-white font-medium py-2 px-4 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-2 transition-colors duration-150">
          Submit Form
        </Button>
        <Modal className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50 backdrop-blur-sm">
          <Dialog className="bg-white p-6 rounded-lg shadow-xl max-w-sm w-full animate-fade-in">
            {({ close }) => (
              <>
                <Heading slot="title" className="text-xl font-bold mb-4">Form Submitted Successfully!</Heading>
                <Text className="text-gray-700 mb-6">Thank you for contacting us. We will get back to you shortly.</Text>
                <Button
                  onPress={close}
                  className="w-full bg-gray-200 text-gray-800 font-medium py-2 px-4 rounded-md hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-offset-2 transition-colors duration-150"
                >
                  Close
                </Button>
              </>
            )}
          </Dialog>
        </Modal>
      </DialogTrigger>
    </form>
  );
}

export default MyForm;

view raw JSON →