Skip to content

Commit d87cc44

Browse files
authored
docs: Add initial Autocomplete docs (#7581)
* docs: Add initial Autocomplete docs * Fix docs ts check * rename import
1 parent af56de0 commit d87cc44

File tree

4 files changed

+133
-6
lines changed

4 files changed

+133
-6
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{/* Copyright 2025 Adobe. All rights reserved.
2+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License. You may obtain a copy
4+
of the License at http://www.apache.org/licenses/LICENSE-2.0
5+
Unless required by applicable law or agreed to in writing, software distributed under
6+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
7+
OF ANY KIND, either express or implied. See the License for the specific language
8+
governing permissions and limitations under the License. */}
9+
10+
import {Layout} from '@react-spectrum/docs';
11+
export default Layout;
12+
13+
import docs from 'docs:react-aria-components';
14+
import {PropTable, HeaderInfo, TypeLink, PageDescription, StateTable, ContextTable} from '@react-spectrum/docs';
15+
import styles from '@react-spectrum/docs/src/docs.css';
16+
import packageData from 'react-aria-components/package.json';
17+
import ChevronRight from '@spectrum-icons/workflow/ChevronRight';
18+
import {InlineAlert, Content, Heading} from '@adobe/react-spectrum';
19+
20+
---
21+
category: Pickers
22+
keywords: [autocomplete, search, menu, command palette, aria]
23+
type: component
24+
preRelease: alpha
25+
---
26+
27+
# Autocomplete
28+
29+
<PageDescription>{docs.exports.UNSTABLE_Autocomplete.description}</PageDescription>
30+
31+
<HeaderInfo
32+
packageData={packageData}
33+
componentNames={['UNSTABLE_Autocomplete']}
34+
sourceData={[
35+
{type: 'W3C', url: 'https://w3c.github.io/aria/#aria-autocomplete'}
36+
]} />
37+
38+
<InlineAlert variant="notice" marginTop={60}>
39+
<Heading>Under construction</Heading>
40+
<Content>This component is in <strong>alpha</strong>. More documentation is coming soon!</Content>
41+
</InlineAlert>
42+
43+
## Example
44+
45+
```tsx example
46+
import {UNSTABLE_Autocomplete as Autocomplete, Menu, MenuItem, useFilter} from 'react-aria-components';
47+
import {MySearchField} from './SearchField';
48+
49+
function Example() {
50+
let {contains} = useFilter({sensitivity: 'base'});
51+
return (
52+
<div className="autocomplete">
53+
<Autocomplete filter={contains}>
54+
<MySearchField placeholder="Search commands..." />
55+
<Menu>
56+
<MenuItem>Create new file...</MenuItem>
57+
<MenuItem>Create new folder...</MenuItem>
58+
<MenuItem>Assign to...</MenuItem>
59+
<MenuItem>Assign to me</MenuItem>
60+
<MenuItem>Change status...</MenuItem>
61+
<MenuItem>Change priority...</MenuItem>
62+
<MenuItem>Add label...</MenuItem>
63+
<MenuItem>Remove label...</MenuItem>
64+
</Menu>
65+
</Autocomplete>
66+
</div>
67+
);
68+
}
69+
```
70+
71+
<details>
72+
<summary style={{fontWeight: 'bold'}}><ChevronRight size="S" /> Show CSS</summary>
73+
```css hidden
74+
@import './Menu.mdx' layer(listbox);
75+
@import './Button.mdx' layer(button);
76+
@import './SearchField.mdx' layer(searchfield);
77+
```
78+
79+
```css
80+
@import "@react-aria/example-theme";
81+
82+
.autocomplete {
83+
display: flex;
84+
flex-direction: column;
85+
gap: 12px;
86+
max-width: 300px;
87+
height: 180px;
88+
border: 1px solid var(--border-color);
89+
padding: 16px;
90+
border-radius: 10px;
91+
background: var(--overlay-background);
92+
93+
.react-aria-SearchField {
94+
width: 100%;
95+
}
96+
97+
.react-aria-Menu {
98+
flex: 1;
99+
overflow: auto;
100+
}
101+
}
102+
```
103+
104+
</details>
105+
106+
## Anatomy
107+
108+
`Autocomplete` is a controller for a child text input, such as a [TextField](TextField.html) or [SearchField](SearchField), and a collection component such as a [Menu](Menu.html) or [ListBox](ListBox.html). It enables the user to filter a list of items, and navigate via the arrow keys while keeping focus on the input.
109+
110+
```tsx
111+
import {UNSTABLE_Autocomplete as Autocomplete, SearchField, Menu} from 'react-aria-components';
112+
113+
<Autocomplete>
114+
<SearchField />
115+
<Menu />
116+
</Autocomplete>
117+
```
118+
119+
## Props
120+
121+
<PropTable component={docs.exports.UNSTABLE_Autocomplete} links={docs.links} />

packages/react-aria-components/docs/SearchField.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ import {SearchField, Label, Input, Button} from 'react-aria-components';
9191
-webkit-appearance: none;
9292
}
9393

94+
&::placeholder {
95+
color: var(--text-color-placeholder);
96+
opacity: 1;
97+
}
98+
9499
&[data-focused] {
95100
outline: 2px solid var(--focus-ring-color);
96101
outline-offset: -1px;
@@ -226,14 +231,15 @@ import {Text, FieldError} from 'react-aria-components';
226231
interface MySearchFieldProps extends SearchFieldProps {
227232
label?: string,
228233
description?: string,
229-
errorMessage?: string | ((validation: ValidationResult) => string)
234+
errorMessage?: string | ((validation: ValidationResult) => string),
235+
placeholder?: string
230236
}
231237

232-
function MySearchField({label, description, errorMessage, ...props}: MySearchFieldProps) {
238+
export function MySearchField({label, description, errorMessage, placeholder, ...props}: MySearchFieldProps) {
233239
return (
234240
<SearchField {...props}>
235-
<Label>{label}</Label>
236-
<Input />
241+
{label && <Label>{label}</Label>}
242+
<Input placeholder={placeholder} />
237243
<Button>✕</Button>
238244
{description && <Text slot="description">{description}</Text>}
239245
<FieldError>{errorMessage}</FieldError>

packages/react-aria-components/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export {UNSTABLE_TreeLoadingIndicator, UNSTABLE_Tree, UNSTABLE_TreeItem, UNSTABL
7878
export {useDragAndDrop} from './useDragAndDrop';
7979
export {DropIndicator, DropIndicatorContext, DragAndDropContext} from './DragAndDrop';
8080
export {Virtualizer as UNSTABLE_Virtualizer} from './Virtualizer';
81-
export {DIRECTORY_DRAG_TYPE, isDirectoryDropItem, isFileDropItem, isTextDropItem, SSRProvider, RouterProvider, I18nProvider, useLocale} from 'react-aria';
81+
export {DIRECTORY_DRAG_TYPE, isDirectoryDropItem, isFileDropItem, isTextDropItem, SSRProvider, RouterProvider, I18nProvider, useLocale, useFilter} from 'react-aria';
8282
export {FormValidationContext} from 'react-stately';
8383
export {parseColor, getColorChannels} from '@react-stately/color';
8484
export {ListLayout as UNSTABLE_ListLayout, GridLayout as UNSTABLE_GridLayout} from '@react-stately/layout';

scripts/extractStarter.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fs.mkdirSync(`starters/docs/src`, {recursive: true});
2929
fs.mkdirSync(`starters/docs/stories`, {recursive: true});
3030

3131
for (let file of glob.sync('packages/react-aria-components/docs/*.mdx')) {
32-
if (!/^[A-Z]/.test(basename(file)) || /^Tree/.test(basename(file))) {
32+
if (!/^[A-Z]/.test(basename(file)) || /^Tree|^Autocomplete/.test(basename(file))) {
3333
continue;
3434
}
3535

0 commit comments

Comments
 (0)