prototype
MAmattpocock/skills336k近 7 天新增 5,004 个 star
Build accessible UI components with React Aria Components. Use when developers mention React Aria, react-aria-components, accessible components, or need unstyled accessible primitives. Provides documentation for building custom accessible UI with hooks and components.
@react-aria/test-utils provides ARIA pattern testers that simulate mouse, keyboard, and touch interactions for components built with React Aria Components.
npm install @react-aria/test-utils --save-dev
External consumers should import from @react-aria/test-utils.
Initialize a User once per test file. Call createTester to get a tester for a specific ARIA pattern, then call tester methods to simulate interactions.
import {User} from '@react-aria/test-utils';
// Provide whatever method of advancing timers you use in your test, this example assumes Jest with fake timers.
// 'interactionType' specifies what mode of interaction should be simulated by the tester
// 'advanceTimer' is used by the tester to advance the timers in the tests for specific interactions (e.g. long press)
let testUtilUser = new User({interactionType: 'mouse', advanceTimer: jest.advanceTimersByTime});
it('my test case', async function () {
// Render your test component/app
let {getByTestId} = render();
// Initialize the table tester via providing the 'Table' pattern name and the root element of said table
let tableTester = testUtilUser.createTester('Table', {root: getByTestId('test_table')});
expect(tableTester.getSelectedRows()).toHaveLength(0);
await tableTester.toggleSelectAll();
expect(tableTester.getSelectedRows()).toHaveLength(10);
...
});
Set interactionType to 'mouse', 'keyboard', or 'touch'. Override per tester via createTester(..., {interactionType}) or per method call.
When using fake timers, pass advanceTimer: jest.advanceTimersByTime and flush timers after each test:
afterEach(() => {
act(() => jest.runAllTimers());
});
advanceTimer.option, row, column, checkbox, radio, tab) take a number (index), string (text content), or HTMLElement. Use the tester's own query methods (e.g. getRows(), getOptions()) to obtain an HTMLElement when you need one.Skip the testers and write manual interactions for the following cases:
fireEvent.keyDown or userEvent.keyboard directly so the test is actually testing the desired keyboard flow.isOpen or defaultOpen is set, open() will no-op but the tester's root must still resolve to the trigger element. Use getByLabelText or getByTestId rather than getByRole('button') to avoid ambiguity when multiple buttons are in the DOM.isDismissible, isKeyboardDismissDisabled, or outside-click behavior. Use userEvent.click(document.body) or user.keyboard('[Escape]') directly and assert the expected state afterwards.dialogTester.getDialog() to assert whether the dialog is still present.Components with draggable handles (Slider, ColorArea, ColorSlider, ColorWheel) need getBoundingClientRect mocked so move calculations work:
import {installMouseEvent} from '@react-aria/test-utils';
installMouseEvent();
beforeAll(() => {
jest.spyOn(window.HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(
() => ({top: 0, left: 0, width: 100, height: 10, bottom: 10, right: 100})
);
});
| Pattern name | Component | Key methods |
|---|---|---|
'CheckboxGroup' | CheckboxGroup | getCheckboxGroup(), getCheckboxes(), getSelectedCheckboxes(), toggleCheckbox({checkbox}) |
'ComboBox' | ComboBox | getCombobox(), getListbox(), getOptions(), open(), toggleOptionSelection({option}) |
'Dialog' | Modal, Popover | getTrigger(), getDialog(), open(), close() — pass overlayType: 'modal' or 'popover' to createTester |
'GridList' | GridList | getGridlist(), getRows(), getSelectedRows(), toggleRowSelection({row}), triggerRowAction({row}) |
'ListBox' | ListBox | getListbox(), getOptions(), getSelectedOptions(), toggleOptionSelection({option}), triggerOptionAction({option}) |
'Menu' | Menu | getTrigger(), getMenu(), getOptions(), open(), toggleOptionSelection({option}), openSubmenu({submenuTrigger}), close() |
'RadioGroup' | RadioGroup | getRadioGroup(), getRadios(), getSelectedRadio(), triggerRadio({radio}) |
'Select' | Select | getTrigger(), getListbox(), getOptions(), toggleOptionSelection({option}) |
'Table' | Table | getTable(), getRows(), getFooterRows(), getColumns(), getSelectedRows(), toggleRowSelection({row}), toggleSort({column}), triggerRowAction({row}) |
'Tabs' | Tabs | getTablist(), getTabs(), getTabpanels(), getSelectedTab(), triggerTab({tab}) |
'Tree' | Tree | getTree(), getRows(), getSelectedRows(), toggleRowSelection({row}), toggleRowExpansion({row}), triggerRowAction({row}) |
The references/ directory contains detailed documentation organized as follows:
Component documentation is in references/components/ — one Markdown file per component (e.g. references/components/Button.md). Read the file for a component when you need its API, props, examples, or accessibility notes.
Available components: Autocomplete, Breadcrumbs, Button, Calendar, Checkbox, CheckboxGroup, ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, ColorWheel, ComboBox, DateField, DatePicker, DateRangePicker, Disclosure, DisclosureGroup, DropZone, FileTrigger, Form, GridList, Group, Link, ListBox, Menu, Meter, Modal, NumberField, Popover, ProgressBar, RadioGroup, RangeCalendar, SearchField, Select, Separator, Slider, Switch, Table, Tabs, TagGroup, TextField, TimeField, Toast, ToggleButton, ToggleButtonGroup, Toolbar, Tooltip, Tree, Virtualizer.
MAmattpocock/skills336k近 7 天新增 5,004 个 star
AFaffaan-m/ECC314k近 7 天新增 4,125 个 star
FIfirecrawl/firecrawl214k近 7 天新增 5,821 个 star
ANanthropics/skills203k近 7 天新增 3,333 个 star
用 React、Tailwind 和 shadcn/ui 构建多组件页面。
ANanthropics/skills203k近 7 天新增 3,333 个 star