Skip to content

Commit 57e57e0

Browse files
committed
add example testing the Autocomplete generic
1 parent 8e75339 commit 57e57e0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/react-aria-components/stories/Autocomplete.stories.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {MyCheckbox} from './Table.stories';
1818
import {MyGridListItem} from './GridList.stories';
1919
import {MyListBoxLoaderIndicator} from './ListBox.stories';
2020
import {MyTag} from './TagGroup.stories';
21+
import {Node} from '@react-types/shared';
2122
import React, {useState} from 'react';
2223
import styles from '../example/index.css';
2324
import {useAsyncList, useListData, useTreeData} from 'react-stately';
@@ -166,7 +167,7 @@ export const AutocompleteSearchfield: AutocompleteStory = {
166167

167168
// Note that the trigger items in this array MUST have an id, even if the underlying MenuItem might apply its own
168169
// id. If it is omitted, we can't build the collection node for the trigger node and an error will throw
169-
let dynamicAutocompleteSubdialog = [
170+
let dynamicAutocompleteSubdialog: MenuNode[] = [
170171
{name: 'Section 1', isSection: true, children: [
171172
{name: 'Command Palette'},
172173
{name: 'Open View'}
@@ -440,7 +441,7 @@ const CaseSensitiveFilter = (args) => {
440441
let defaultFilter = (itemText, input) => contains(itemText, input);
441442

442443
return (
443-
<Autocomplete filter={defaultFilter}>
444+
<Autocomplete<AutocompleteItem> filter={defaultFilter}>
444445
<div>
445446
<SearchField autoFocus>
446447
<Label style={{display: 'block'}}>Test</Label>
@@ -1091,17 +1092,26 @@ export const AutocompleteWithTagGroup = () => {
10911092
);
10921093
};
10931094

1095+
type MenuNode = {
1096+
name: string,
1097+
id?: string,
1098+
isSection?: boolean,
1099+
isMenu?: boolean,
1100+
children?: MenuNode[]
1101+
}
1102+
10941103
function AutocompleteNodeFiltering(args) {
10951104
let {contains} = useFilter({sensitivity: 'base'});
1096-
let filter = (textValue, inputValue, node) => {
1105+
let filter = (textValue: string, inputValue: string, node: Node<MenuNode>) => {
10971106
if ((node.parentKey === 'Section 1' && textValue === 'Open View') || (node.parentKey === 'Section 2' && textValue === 'Appearance')) {
10981107
return true;
10991108
}
1109+
11001110
return contains(textValue, inputValue);
11011111
};
11021112

11031113
return (
1104-
<Autocomplete filter={filter}>
1114+
<Autocomplete<MenuNode> filter={filter}>
11051115
<div>
11061116
<SearchField autoFocus>
11071117
<Label style={{display: 'block'}}>Test</Label>

0 commit comments

Comments
 (0)