Skip to content

Commit

Permalink
Merge pull request #3145 from cherniavskii/AutocompleteArrayInput-sug…
Browse files Browse the repository at this point in the history
…gestionsContainerProps

[AutocompleteArrayInput] Allow to override Popper props
  • Loading branch information
Gildas Garcia authored Apr 19, 2019
2 parents c55cb64 + 8b81361 commit 88e9db9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/Inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ import { AutocompleteArrayInput, ReferenceArrayInput } from 'react-admin'
</ReferenceArrayInput>
```
If you need to override the props of the suggestions container (a `Popper` element), you can specify them using the `options.suggestionsContainerProps`. For example:
{% raw %}
```jsx
<AutocompleteArrayInput source="category" options={{
suggestionsContainerProps: {
disablePortal: true,
}} />
```
{% endraw %}
**Tip**: `<ReferenceArrayInput>` is a stateless component, so it only allows to *filter* the list of choices, not to *extend* it. If you need to populate the list of choices based on the result from a `fetch` call (and if [`<ReferenceArrayInput>`](#referencearrayinput) doesn't cover your need), you'll have to [write your own Input component](#writing-your-own-input-component) based on [material-ui-chip-input](https://github.com/TeamWertarbyte/material-ui-chip-input).
**Tip**: React-admin's `<AutocompleteInput>` has only a capital A, while material-ui's `<AutoComplete>` has a capital A and a capital C. Don't mix up the components!
Expand Down
5 changes: 3 additions & 2 deletions packages/ra-ui-materialui/src/input/AutocompleteArrayInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class AutocompleteArrayInput extends React.Component {
source,
value,
ref,
options: { InputProps, ...options },
options: { InputProps, suggestionsContainerProps, ...options },
...other
} = inputProps;
if (typeof meta === 'undefined') {
Expand Down Expand Up @@ -366,7 +366,7 @@ export class AutocompleteArrayInput extends React.Component {
containerProps: { className, ...containerProps },
children,
} = autosuggestOptions;
const { classes = {} } = this.props;
const { classes = {}, options } = this.props;

// Force the Popper component to reposition the popup only when this.inputEl is moved to another location
this.updateAnchorEl();
Expand All @@ -377,6 +377,7 @@ export class AutocompleteArrayInput extends React.Component {
open={Boolean(children)}
anchorEl={this.anchorEl}
placement="bottom-start"
{...options.suggestionsContainerProps}
>
<Paper
square
Expand Down
23 changes: 23 additions & 0 deletions packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,27 @@ describe('<AutocompleteArrayInput />', () => {
}, 250);
});
});

it('passes options.suggestionsContainerProps to the suggestions container', () => {
const onChange = jest.fn();

const wrapper = mount(
<AutocompleteArrayInput
{...defaultProps}
input={{ value: [], onChange }}
choices={[
{ id: 1, name: 'ab' },
{ id: 2, name: 'abc' },
{ id: 3, name: '123' },
]}
options={{
suggestionsContainerProps: {
disablePortal: true,
}
}}
/>,
{ context, childContextTypes }
);
expect(wrapper.find('Popper').props().disablePortal).toEqual(true);
});
});

0 comments on commit 88e9db9

Please sign in to comment.