Skip to content

Commit

Permalink
AutocompleteArrayInput suggestionLimit prop - test cases and docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarbakhtar committed Jun 11, 2019
1 parent 95a8e26 commit fc83050
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/Inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ If you need to override the props of the suggestions container (a `Popper` eleme
| `optionText` | Optional | <code>string &#124; Function</code> | `name` | Fieldname of record to display in the suggestion item or function which accepts the current record as argument (`(record)=> {string}`) |
| `setFilter` | Optional | `Function` | null | A callback to inform the `searchText` has changed and new `choices` can be retrieved based on this `searchText`. Signature `searchText => void`. This function is automatically setup when using `ReferenceInput`. |
| `suggestionComponent` | Optional | Function | `({ suggestion, query, isHighlighted, props }) => <div {...props} />` | Allows to override how the item is rendered. |
| `suggestionLimit` | Optional | Number | null | Limits the numbers of suggestions that are shown in the dropdown list |
| `shouldRenderSuggestions` | Optional | Function | `() => true` | A function that returns a `boolean` to determine whether or not suggestions are rendered. Use this when working with large collections of data to improve performance and user experience. This function is passed into the underlying react-autosuggest component. Ex.`(value) => value.trim() > 2` |
## `<BooleanInput>` and `<NullableBooleanInput>`
Expand Down
14 changes: 14 additions & 0 deletions packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,18 @@ describe('<AutocompleteArrayInput />', () => {
wrapper.find('ForwardRef(Popper)').props().disablePortal
).toEqual(true);
});

it('should limit suggestions when suggestionLimit is passed', () => {
const wrapper = shallow(
<AutocompleteArrayInput
{...defaultProps}
choices={[
{ id: 'M', name: 'Male' },
{ id: 'F', name: 'Female' },
]}
suggestionLimit={1}
/>
);
expect(wrapper.state('suggestions')).toHaveLength(1);
});
});

0 comments on commit fc83050

Please sign in to comment.