UNPKG

15.2 kBMarkdownView Raw
1# Upgrade Guide
2
3- [Version 6.0](Upgrading.md#v60-breaking-changes)
4- [Version 5.0](Upgrading.md#v50-breaking-changes)
5- [Version 4.0](Upgrading.md#v40-breaking-changes)
6- [Version 3.0](Upgrading.md#v30-breaking-changes)
7- [Version 2.0](Upgrading.md#v20)
8- [Version 1.0](Upgrading.md#v10)
9
10## v6.0 Breaking Changes
11
12### `"small"` and `"large"` are no longer valid `size` values
13The `size` prop previously accepted `"small"` and `"large"` as valid values but now only accepts `"sm"` or `"lg"`. This better reflects Bootstrap classnames and related libraries like [React-Bootstrap](https://react-bootstrap.github.io/forms/form-control/#form-control-props).
14
15### `shouldSelectHint` replaced by top-level `selectHint`
16The `shouldSelectHint` prop was introduced as in v5 as a more flexible way to control hint selection. However, the implementation was still limited and not very convenient to use. v6 introduces `selectHint` as a top-level prop that can be used to control hint selection more easily. The signature for `selectHint` remains the same as `shouldSelectHint`:
17
18#### v5
19```jsx
20<Typeahead
21 ...
22 inputProps={{
23 shouldSelectHint: (shouldSelect, event) => (
24 event.key === "Enter" || shouldSelect;
25 )
26 }}
27/>
28```
29
30#### v6
31```jsx
32<Typeahead
33 ...
34 selectHint={(shouldSelect, event) => (
35 event.key === "Enter" || shouldSelect;
36 )}
37/>
38```
39
40### Removed `selectHintOnEnter`
41This prop was deprecated in v5 and is now gone. Use `selectHint` instead.
42
43### PopperJS upgraded to v2
44This should mostly be a transparent change. However, PopperJS now triggers the following warning in development:
45
46```js
47Popper: CSS "margin" styles cannot be used to apply padding between the popper and its reference element or boundary. To replicate margin, use the `offset` modifier, as well as the `padding` option in the `preventOverflow` and `flip` modifiers.
48```
49This is due to an [inherent conflict](https://github.com/react-bootstrap/react-bootstrap/issues/5081) between Bootstrap styles and PopperJS v2. There have been no observed issues in this library, but it's possible you may experience some visual glitches when the menu changes position. The warning should go away in a future major version when support for Bootstrap 4 is dropped.
50
51### Refs can no longer be passed via `inputProps`
52If you need to access the input node, use the [public `getInput` method](Methods.md).
53
54### Removed `asyncContainer`, `menuItemContainer`, `tokenContainer` HOCs
55These were deprecated in v5 and renamed to `withAsync`, `withItem`, and `withToken`, respectively.
56
57### Drop support for IE11
58It's time. Edge is still supported.
59
60## v5.0 Breaking Changes
61
62### Drop support for React < 16.8
63This library now relies on [hooks](https://reactjs.org/docs/hooks-intro.html), both in the package itself as well as underlying dependencies. You must upgrade your version of React and ReactDOM to be at least 16.8
64
65### Drop official support for Bootstrap 3
66Among other things, this consists of updating the HTML structure and class names of included components like `MenuItem` in a backwards-incompatible way. Note that if you are using BS3, things should still work, but you may need to render your own menu, menu item, and input components.
67
68### Remove `getInstance` method
69The `getInstance` method was deprecated in v4.2.0 and has been removed. You can access instance methods on the `ref` itself.
70
71### `AsyncTypeahead` rewritten with hooks
72This should generally be a transparent change. There is at least one instance where it could break existing code, however: if your `onSearch` handler is re-instantiated on each render, this will cancel the debounced function and potentially prevent `onSearch` from being called. To avoid this, either [bind the handler in the constructor or use class properties](https://reactjs.org/docs/faq-functions.html#how-do-i-bind-a-function-to-a-component-instance) (if using a class component) or [use `useCallback` with a dependency array](https://reactjs.org/docs/hooks-reference.html#usecallback) (if using a functional component):
73
74```jsx
75// This may cause problems:
76<AsyncTypeahead
77 ...
78 onSearch={(query) => {
79 // Do stuff...
80 }}
81/>
82
83// Instead, do one of the following:
84class MyComponent extends React.Component {
85 render () {
86 <AsyncTypeahead
87 ...
88 onSearch={this.handleSearch}
89 />
90 }
91
92 handleSearch = (query) => {
93 // Do stuff...
94 }
95}
96
97const MyComponent = () => {
98 const handleSearch = useCallback((query) => {
99 // Do stuff...
100 }, []);
101
102 return (
103 <AsyncTypeahead
104 ...
105 onSearch={handleSearch}
106 />
107 );
108};
109```
110
111
112
113For more, [see issue #561](https://github.com/ericgio/react-bootstrap-typeahead/issues/561).
114
115### Remove `findDOMNode`
116`findDOMNode` was deprecated in React 16.3 and all uses of it (including dependencies) are now gone. In some cases, this now requires explicitly passing refs to underlying DOM nodes.
117
118When using `renderInput`, you will need to pass both the `inputRef` and `referenceElementRef` prop to a DOM node. This will usually be the input itself, but may be a container node:
119
120```jsx
121<Typeahead
122 ...
123 renderInput={({ inputRef, referenceElementRef, ...inputProps }) => (
124 <Form.Control
125 {...inputProps}
126 ref={(inputNode) => {
127 inputRef(inputNode);
128 referenceElementRef(inputNode);
129 }}
130 />
131 )}
132/>
133```
134
135When using custom tokens, you will need to pass the ref from `withToken` to the token's DOM node:
136```jsx
137const MyToken = withToken(forwardRef((props, ref) => (
138 <div
139 className="my-token"
140 ref={ref}>
141 {props.children}
142 </div>
143)));
144```
145
146### `hintContainer` HOC is now `Hint` component
147Rewriting the HOC as a component makes it a little easier to use and better reflects its relationship with the input.
148
149#### v4.x
150```jsx
151import { Form } from 'react-bootstrap';
152import { Typeahead, hintContainer } from 'react-bootstrap-typeahead';
153
154const FormControlWithHint = hintContainer(Form.Control);
155
156<Typeahead
157 ...
158 renderInput={(...) => (
159 <FormControlWithHint {...} />
160 )}
161/>
162```
163
164#### v5.0
165```jsx
166import { Form } from 'react-bootstrap';
167import { Typeahead, Hint } from 'react-bootstrap-typeahead';
168
169<Typeahead
170 ...
171 renderInput={(...) => (
172 <Hint>
173 <Form.Control {...} />
174 </Hint>
175 )}
176/>
177```
178
179### Rename `bsSize` prop to `size`
180The `bsSize` prop was deprecated in v4.2.0 and has been removed. Use `size` instead.
181
182### Increase specificity of multi-select component style
183This change is only relevant if you are overriding the `.rbt-input-multi` CSS class. It increases the CSS specificity for the input's height to make the styling less dependent on stylesheet ordering and thus less likely to break.
184
185## v4.0 Breaking Changes
186
187### Drop support for older versions of React
188React and ReactDOM >=16.3 are now required as peer dependencies.
189
190### Props
191- `onMenuHide` and `onMenuShow` were removed. Use `onMenuToggle` instead.
192
193### When using custom menu items, you must manually pass a ref to the underlying DOM node.
194`tokenContainer` no longer uses `findDOMNode`, and instead passes a `ref` to the wrapped component. If you are using your own menu item component to render the menu, you must forward that ref to the underlying DOM node.
195
196### `option` is now required for a `Token` to be removeable
197Pass `option` as a prop to `Token` (or `tokenContainer` if using your own token markup) so the container can correctly handle the `onRemove` callback.
198
199```jsx
200<Typeahead
201 ...
202 renderToken={(option, props, idx) => (
203 <Token
204 ...
205 onRemove={props.onRemove}
206 option={option}>
207 {option.label}
208 </Token>
209 )}
210/>
211```
212
213
214### Falsy `emptyLabel` no longer hides the menu when there are no results
215This behavior was a legacy workaround introduced before `renderMenu` could return `null`. That is no longer the case and `renderMenu` should now be used to achieve the behavior:
216
217```jsx
218<Typeahead
219 ...
220 renderMenu={(results, menuProps) => {
221 if (!results.length) {
222 return null;
223 }
224
225 return <TypeaheadMenu {...menuProps} />;
226 }}
227/>
228```
229
230### `id` required for assistive technologies
231The `menuId` prop has been replaced by `id` and no longer provides a default value. You must provide an id for assistive technologies like screen readers.
232
233### Input `autoComplete` attribute defaults to "off"
234Behavior is now correct according to a11y standards, but may result in unexpected behaviors since different browsers handle this attribute differently.
235
236- To keep the previous behavior, pass "nope" value in `inputProps`.
237
238### Updates to the `Overlay` component
239Overlay was updated to take advantage of Popper.js' fixed positioning rather than using a portal to attach the menu to the document body. This greatly simplifies the component and gives greater control over styling.
240
241- `bodyContainer` props was removed. Use `positionFixed` instead.
242- Use of `.rbt-body-container` for CSS scoping will no longer work. Pass your own scoping classnames to the component instead.
243
244### A11y announcer removed
245This piece of functionality is not part of the WAI-ARIA authoring guidelines and was difficult to test and support.
246
247- `a11yNumResults` & `a11yNumSelected` are now no-ops
248- If you need this functionality, you can add it yourself as a child (or child function) of the component.
249
250## v3.0 Breaking Changes
251
252### Props
253- The `name` prop was deprecated in v2.0 and is now gone.
254- Non-string values for the `maxHeight` prop were deprecated in v2.5 and are now no longer allowed.
255
256### Changes to `filterBy` and `renderToken` callback signatures
257
258#### `filterBy`
259If you [pass a callback to `filterBy`]((Filtering.md#functionoption-objectstring-text-string)), it will now receive the set of internal props as the second parameter instead of the user-input `text` value:
260
261```jsx
262// v2.0
263<Typeahead
264 ...
265 filterBy={(option, text) => {
266 // Your own filtering code goes here.
267 }}
268/>
269
270// v3.0
271<Typeahead
272 ...
273 filterBy={(option, props) => {
274 // Your own filtering code goes here.
275 // `text` is now `props.text`
276 }}
277/>
278```
279#### `renderToken`
280Similarly, [`renderToken`](Rendering.md#rendertokenoption-objectstring-onremove-function-index-number) now receives internal props as the second param rather than just the `onRemove` function:
281
282```jsx
283// v2.0
284<Typeahead
285 ...
286 multiple
287 renderToken={(option, onRemove, index) => {
288 // Your own token rendering code.
289 }}
290/>
291
292// v3.0
293<Typeahead
294 ...
295 multiple
296 renderToken={(option, props, index) => {
297 // Your own token rendering code.
298 // `onRemove` is now `props.onRemove`
299 }}
300/>
301```
302
303### Internal changes & CSS
304This version includes some significant internal refactoring in an effort to provide better support for Bootstrap 4. If you have custom CSS that depends on internal (eg: `rbt-*`) classnames, you should check to make sure things still work as you expect.
305
306### Query normalization in `AsyncTypeahead`
307`AsyncTypeahead` no longer trims whitespace on or lowercases queries. The original intent was to provide some basic normalization of queries, but this resulted in strange behaviors. You should now do any checking you want, like ignoring queries with only whitespace, in your `onSearch` function.
308
309### Change events no longer triggered by prop changes
310The `onChange` and `onInputChange` callbacks were previously called in `componentWillReceiveProps`, which triggered multiple calls and didn't emulate how a normal form element works. These change callbacks are now only triggered by user actions, eg: typing in the input, clicking on a menu item, etc. You may need to update your code if it relied on a change event being triggered due to prop changes.
311
312### Custom menu rendering
313Finally, if you use the `renderMenu` prop, a couple changes were made that may affect you:
314
315#### Popper.js for positioning
316The typeahead now uses [Popper.js](https://popper.js.org/) (via [`react-popper`](https://github.com/souporserious/react-popper)) for menu positioning. If you're using the provided `Menu` component inside `renderMenu`, simply pass down all the menu props and everything should work fine. If you're using your own component to render the menu, be sure it properly consumes the `innerRef` prop that gets passed down or the component will not work correctly:
317
318```jsx
319class MyCustomMenu extends React.Component {
320 render() {
321 // `innerRef` is passed down by the Popper...
322 const {innerRef, ...props} = this.props;
323
324 // ...and must be passed to the `ref` of your custom component.
325 return <div {...props} ref={innerRef} />;
326 }
327}
328```
329
330#### Manual handling of pagination option
331To make the pagination menu item keyboard-accessible, it is no longer automatically included in the `Menu` component. Instead, it is added to the result set, similar to the custom (`allowNew`) item. That means you must now handle rendering of the pagination item yourself if you want pagination. See [`TypeaheadMenu`](../src/TypeaheadMenu.react.js) for an example of how to do this.
332
333## v2.0
334Version 2.0 consists mainly of internal refactoring aimed at reducing parallel code paths and making certain complex feature requests possible. These changes should mostly be transparent, though you may notice that the component behaves a bit differently.
335
336### Breaking Changes
337#### `AsyncTypeahead`
338The `AsyncTypeahead` component now requires the request state to be managed externally. Use the `isLoading` prop to tell the component if a request is pending or not. See [the example](https://github.com/ericgio/react-bootstrap-typeahead/blob/master/example/examples/AsyncExample.react.js) for an illustration of proper usage.
339
340#### CSS Changes
341In an effort to simplify the CSS and as a result of the refactor, class names for the various internal components were changed. This may cause styling to break if you relied on a certain naming scheme. The separate CSS files were also combined into a single file (`Typeahead.css`) to make it easier to include.
342
343### Deprecations
344- The `name` prop is now deprecated and will be removed in v3.0. Use `inputProps` to apply props directly to the input instead.
345
346## v1.0
347Version 1.0 has a few breaking changes, but upgrading should be relatively painless.
348
349### Importing
350The main change affecting all users is that the typeahead is now a property of the module:
351
352```jsx
353// v0.10.x
354import Typeahead from 'react-bootstrap-typeahead'; // ES2015
355var Typeahead = require('react-bootstrap-typeahead').default; // CommonJS
356
357// v1.x
358import {Typeahead} from 'react-bootstrap-typeahead'; // ES2015
359var Typeahead = require('react-bootstrap-typeahead').Typeahead; // CommonJS
360```
361
362### `paginateResults`
363This prop was deprecated in v0.9.0 and is now gone.
364
365### `renderMenuItemChildren`
366The signature for the `renderMenuItemChildren` callback was changed such that the data item is now the first argument and props are second. This felt more logical and [all such `render` functions](Rendering.md#rendermenu) follow a similar pattern.
367
368```jsx
369// v0.10.x
370renderMenuItemChildren(props, result, index) {
371 // Rendering code here...
372}
373
374// v1.x
375renderMenuItemChildren(result, props, index) {
376 // Rendering code here...
377}
378```
379
380That should be everything. If you come across something I missed, please open an issue. Thanks!
381
382[Next: Basic Usage](Usage.md)