react-modal 是一个流行的模态对话框库,提供了简单易用的 API 来创建模态窗口。它内置了焦点管理功能,确保用户在模态对话框打开时,焦点不会转移到页面的其他部分。对于需要实现模态对话框的应用程序,react-modal 提供了一个全面的解决方案。
react-portal 是一个用于在 React 应用程序中创建门户的库,允许开发者将子组件渲染到 DOM 的不同位置。虽然它本身不专注于焦点管理,但可以与其他库结合使用,以实现更复杂的用户界面和焦点控制。如果你的应用程序需要在不同的 DOM 节点中渲染组件,react-portal 是一个很好的选择。
A library of React Hooks that provides accessible UI primitives for your design system.
Features
♿️ Accessible – React Aria provides accessibility and behavior according to WAI-ARIA Authoring Practices, including full screen reader and keyboard navigation support. All components have been tested across a wide variety of screen readers and devices to ensure the best experience possible for all users.
📱 Adaptive – React Aria ensures consistent behavior, no matter the UI. It supports mouse, touch, keyboard, and screen reader interactions that have been tested across a wide variety of browsers, devices, and platforms.
🌍 International – React Aria supports over 30 languages, including right-to-left-specific behavior, internationalized date and number formatting, and more.
🎨 Fully customizable – React Aria doesn’t implement any rendering or impose a DOM structure, styling methodology, or design-specific details. It provides behavior, accessibility, and interactions and lets you focus on your design.
Getting started
The easiest way to start building a component library with React Aria is by following our getting started guide. It walks through all of the steps needed to install the hooks from npm, and create your first component.
Example
Here is a very basic example of using React Aria.
import {useButton} from '@react-aria/button';
function Button(props) {
let ref = React.useRef();
let {buttonProps} = useButton(props, ref);
return (
<button {...buttonProps} ref={ref}>
{props.children}
</button>
);
}
<Button onPress={() => alert('Button pressed!')}>Press me</Button>
Learn more
React Aria is part of a family of libraries that help you build adaptive, accessible, and robust user experiences.
Learn more about React Spectrum and React Stately on our website.