UNPKG

12.8 kBMarkdownView Raw
1# Upgrade Guide
2
3- [Version 5.0](Upgrading.md#v50-breaking-changes)
4- [Version 4.0](Upgrading.md#v40-breaking-changes)
5- [Version 3.0](Upgrading.md#v30-breaking-changes)
6- [Version 2.0](Upgrading.md#v20)
7- [Version 1.0](Upgrading.md#v10)
8
9## v5.0 Breaking Changes
10
11### Drop support for React < 16.8
12This 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
13
14### Drop official support for Bootstrap 3
15Among 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.
16
17### Remove `getInstance` method
18The `getInstance` method was deprecated in v4.2.0 and has been removed. You can access instance methods on the `ref` itself.
19
20### `AsyncTypeahead` rewritten with hooks
21This 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):
22
23```jsx
24// This may cause problems:
25<AsyncTypeahead
26 ...
27 onSearch={(query) => {
28 // Do stuff...
29 }}
30/>
31
32// Instead, do one of the following:
33class MyComponent extends React.Component {
34 render () {
35 <AsyncTypeahead
36 ...
37 onSearch={this.handleSearch}
38 />
39 }
40
41 handleSearch = (query) => {
42 // Do stuff...
43 }
44}
45
46const MyComponent = () => {
47 const handleSearch = useCallback((query) => {
48 // Do stuff...
49 }, []);
50
51 return (
52 <AsyncTypeahead
53 ...
54 onSearch={handleSearch}
55 />
56 );
57};
58```
59
60
61
62For more, [see issue #561](https://github.com/ericgio/react-bootstrap-typeahead/issues/561).
63
64### Remove `findDOMNode`
65`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.
66
67When 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:
68
69```jsx
70<Typeahead
71 ...
72 renderInput={({ inputRef, referenceElementRef, ...inputProps }) => (
73 <Form.Control
74 {...inputProps}
75 ref={(inputNode) => {
76 inputRef(inputNode);
77 referenceElementRef(inputNode);
78 }}
79 />
80 )}
81/>
82```
83
84When using custom tokens, you will need to pass the ref from `withToken` to the token's DOM node:
85```jsx
86const MyToken = withToken(forwardRef((props, ref) => (
87 <div
88 className="my-token"
89 ref={ref}>
90 {props.children}
91 </div>
92)));
93```
94
95### `hintContainer` HOC is now `Hint` component
96Rewriting the HOC as a component makes it a little easier to use and better reflects its relationship with the input.
97
98#### v4.x
99```jsx
100import { Form } from 'react-bootstrap';
101import { Typeahead, hintContainer } from 'react-bootstrap-typeahead';
102
103const FormControlWithHint = hintContainer(Form.Control);
104
105<Typeahead
106 ...
107 renderInput={(...) => (
108 <FormControlWithHint {...} />
109 )}
110/>
111```
112
113#### v5.0
114```jsx
115import { Form } from 'react-bootstrap';
116import { Typeahead, Hint } from 'react-bootstrap-typeahead';
117
118<Typeahead
119 ...
120 renderInput={(...) => (
121 <Hint>
122 <Form.Control {...} />
123 </Hint>
124 )}
125/>
126```
127
128### Rename `bsSize` prop to `size`
129The `bsSize` prop was deprecated in v4.2.0 and has been removed. Use `size` instead.
130
131### Increase specificity of multi-select component style
132This 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.
133
134## v4.0 Breaking Changes
135
136### Drop support for older versions of React
137React and ReactDOM >=16.3 are now required as peer dependencies.
138
139### Props
140- `onMenuHide` and `onMenuShow` were removed. Use `onMenuToggle` instead.
141
142### When using custom menu items, you must manually pass a ref to the underlying DOM node.
143`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.
144
145### `option` is now required for a `Token` to be removeable
146Pass `option` as a prop to `Token` (or `tokenContainer` if using your own token markup) so the container can correctly handle the `onRemove` callback.
147
148```jsx
149<Typeahead
150 ...
151 renderToken={(option, props, idx) => (
152 <Token
153 ...
154 onRemove={props.onRemove}
155 option={option}>
156 {option.label}
157 </Token>
158 )}
159/>
160```
161
162
163### Falsy `emptyLabel` no longer hides the menu when there are no results
164This 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:
165
166```jsx
167<Typeahead
168 ...
169 renderMenu={(results, menuProps) => {
170 if (!results.length) {
171 return null;
172 }
173
174 return <TypeaheadMenu {...menuProps} />;
175 }}
176/>
177```
178
179### `id` required for assistive technologies
180The `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.
181
182### Input `autoComplete` attribute defaults to "off"
183Behavior is now correct according to a11y standards, but may result in unexpected behaviors since different browsers handle this attribute differently.
184
185- To keep the previous behavior, pass "nope" value in `inputProps`.
186
187### Updates to the `Overlay` component
188Overlay 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.
189
190- `bodyContainer` props was removed. Use `positionFixed` instead.
191- Use of `.rbt-body-container` for CSS scoping will no longer work. Pass your own scoping classnames to the component instead.
192
193### A11y announcer removed
194This piece of functionality is not part of the WAI-ARIA authoring guidelines and was difficult to test and support.
195
196- `a11yNumResults` & `a11yNumSelected` are now no-ops
197- If you need this functionality, you can add it yourself as a child (or child function) of the component.
198
199## v3.0 Breaking Changes
200
201### Props
202- The `name` prop was deprecated in v2.0 and is now gone.
203- Non-string values for the `maxHeight` prop were deprecated in v2.5 and are now no longer allowed.
204
205### Changes to `filterBy` and `renderToken` callback signatures
206
207#### `filterBy`
208If 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:
209
210```jsx
211// v2.0
212<Typeahead
213 ...
214 filterBy={(option, text) => {
215 // Your own filtering code goes here.
216 }}
217/>
218
219// v3.0
220<Typeahead
221 ...
222 filterBy={(option, props) => {
223 // Your own filtering code goes here.
224 // `text` is now `props.text`
225 }}
226/>
227```
228#### `renderToken`
229Similarly, [`renderToken`](Rendering.md#rendertokenoption-objectstring-onremove-function-index-number) now receives internal props as the second param rather than just the `onRemove` function:
230
231```jsx
232// v2.0
233<Typeahead
234 ...
235 multiple
236 renderToken={(option, onRemove, index) => {
237 // Your own token rendering code.
238 }}
239/>
240
241// v3.0
242<Typeahead
243 ...
244 multiple
245 renderToken={(option, props, index) => {
246 // Your own token rendering code.
247 // `onRemove` is now `props.onRemove`
248 }}
249/>
250```
251
252### Internal changes & CSS
253This 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.
254
255### Query normalization in `AsyncTypeahead`
256`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.
257
258### Change events no longer triggered by prop changes
259The `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.
260
261### Custom menu rendering
262Finally, if you use the `renderMenu` prop, a couple changes were made that may affect you:
263
264#### Popper.js for positioning
265The 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:
266
267```jsx
268class MyCustomMenu extends React.Component {
269 render() {
270 // `innerRef` is passed down by the Popper...
271 const {innerRef, ...props} = this.props;
272
273 // ...and must be passed to the `ref` of your custom component.
274 return <div {...props} ref={innerRef} />;
275 }
276}
277```
278
279#### Manual handling of pagination option
280To 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.
281
282## v2.0
283Version 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.
284
285### Breaking Changes
286#### `AsyncTypeahead`
287The `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.
288
289#### CSS Changes
290In 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.
291
292### Deprecations
293- The `name` prop is now deprecated and will be removed in v3.0. Use `inputProps` to apply props directly to the input instead.
294
295## v1.0
296Version 1.0 has a few breaking changes, but upgrading should be relatively painless.
297
298### Importing
299The main change affecting all users is that the typeahead is now a property of the module:
300
301```jsx
302// v0.10.x
303import Typeahead from 'react-bootstrap-typeahead'; // ES2015
304var Typeahead = require('react-bootstrap-typeahead').default; // CommonJS
305
306// v1.x
307import {Typeahead} from 'react-bootstrap-typeahead'; // ES2015
308var Typeahead = require('react-bootstrap-typeahead').Typeahead; // CommonJS
309```
310
311### `paginateResults`
312This prop was deprecated in v0.9.0 and is now gone.
313
314### `renderMenuItemChildren`
315The 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.
316
317```jsx
318// v0.10.x
319renderMenuItemChildren(props, result, index) {
320 // Rendering code here...
321}
322
323// v1.x
324renderMenuItemChildren(result, props, index) {
325 // Rendering code here...
326}
327```
328
329That should be everything. If you come across something I missed, please open an issue. Thanks!
330
331[Next: Basic Usage](Usage.md)