Skip to content

Commit 605d680

Browse files
committed
Update docs
1 parent 5d627a6 commit 605d680

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

docs/Rendering.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ Provides flexibility for rendering the typeahead's input. `inputProps` are any i
5353
### `renderMenu(results: Array<Object|String>, menuProps: Object, state: Object)`
5454
Provides flexibility for rendering the typeahead's menu. `results` are the subset of options after they have been filtered and paginated. `menuProps` are any menu-relevant props passed down from the `Typeahead` component. You can also just set props directly on your `Menu`.
5555

56-
Along with stylistic customization, the `renderMenu` hook allows you to do things like re-sort or group your data. Note that if you manipulate data in this way, you *must* use either the provided `MenuItem` component or the [appropriate hook or HOC](API.md#useitem--withitem) to ensure proper behavior.
56+
Along with stylistic customization, the `renderMenu` hook allows you to do things like re-sort or group your data. Note that if you manipulate data in this way, you *must* use either the provided `MenuItem` component or the [appropriate hook](API.md#useitem) to ensure proper behavior.
5757

5858
```jsx
5959
<Typeahead
60-
options={options}
61-
renderMenu={(results, menuProps) => (
60+
...
61+
renderMenu={(results, { onItemSelect, ...menuProps }) => (
6262
<Menu {...menuProps}>
6363
{results.map((result, index) => (
64-
<MenuItem option={result} position={index}>
64+
<MenuItem
65+
key={...}
66+
onClick={() => onItemSelect(result)}
67+
option={result}
68+
position={index}>
6569
{result.label}
6670
</MenuItem>
6771
))}
@@ -99,6 +103,6 @@ Provides the ability to customize rendering of tokens when multiple selections a
99103
/>
100104
```
101105

102-
Be careful when using `renderToken`, since you will need to handle things like disabling the tokens and removing them (via `props.onRemove`) yourself. It is highly recommended that you use the provided `Token` component. If you want to use a completely custom token, use either the provided [hook or HOC](API.md#usetoken--withtoken) to retain keystroke behaviors.
106+
Be careful when using `renderToken`, since you will need to handle things like disabling the tokens and removing them (via `props.onRemove`) yourself. It is highly recommended that you use the provided `Token` component. If you want to use a completely custom token, use either the provided [hook](API.md#usetoken) to retain keystroke behaviors.
103107

104108
[Next: Public Methods](Methods.md)

docs/Upgrading.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@
1010

1111
## v7.0 Breaking Changes
1212

13+
### Explicitly pass `onItemSelect` to `MenuItem`
14+
Previously, `onItemSelect` was transparently passed to menu item components using `useItem`. With v7, that callback must be explicitly passed to menu items via the `onClick` prop. If you are using `renderMenu` to customize your menu you will need to pass `onItemSelect`, which is now available in `menuProps`, to your menu items:
15+
16+
```tsx
17+
<Typeahead
18+
...
19+
renderMenu={(results, { onItemSelect, ...menuProps }) => (
20+
<Menu {...menuProps}>
21+
{results.map((result, index) => (
22+
<MenuItem
23+
key={...}
24+
onClick={() => onItemSelect(result)}
25+
option={result}
26+
position={index}>
27+
{result.label}
28+
</MenuItem>
29+
))}
30+
</Menu>
31+
)}
32+
/>
33+
```
34+
35+
While this change adds a bit more work for custom rendering cases, it provides much more flexibility in terms of choosing how menu interactions work. You can now choose to have a menu item trigger a different action entirely (eg: select all) by omitting `onItemSelect` and passing your own callback to the given item.
36+
1337
### HOCs removed in favor of hooks
1438
The following HOCs were deprecated in a previous version and have been removed:
1539

0 commit comments

Comments
 (0)