Skip to content

Commit

Permalink
[Autocomplete] support for limitTags={0} (#20815)
Browse files Browse the repository at this point in the history
  • Loading branch information
tykdn committed May 2, 2020
1 parent d798533 commit 3d8278a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/Autocomplete/Autocomplete.js
Expand Up @@ -350,7 +350,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {

if (limitTags > -1 && Array.isArray(startAdornment)) {
const more = startAdornment.length - limitTags;
if (limitTags && !focused && more > 0) {
if (!focused && more > 0) {
startAdornment = startAdornment.splice(0, limitTags);
startAdornment.push(
<span className={classes.tag} key={startAdornment.length}>
Expand Down
23 changes: 23 additions & 0 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Expand Up @@ -164,6 +164,29 @@ describe('<Autocomplete />', () => {
expect(container.textContent).to.equal('onetwothree');
expect(tags.length).to.be.equal(5);
});

it('show 0 item on close when set 0 to limitTags', () => {
const { container, getAllByRole, getByRole } = render(
<Autocomplete
multiple
limitTags={0}
{...defaultProps}
options={['one', 'two', 'three']}
defaultValue={['one', 'two', 'three']}
renderInput={(params) => <TextField {...params} />}
/>,
);

let tags;
tags = getAllByRole('button');
expect(container.textContent).to.equal('+3');
expect(tags.length).to.be.equal(2);

getByRole('textbox').focus();
tags = getAllByRole('button');
expect(container.textContent).to.equal('onetwothree');
expect(tags.length).to.be.equal(5);
});
});

describe('prop: filterSelectedOptions', () => {
Expand Down

0 comments on commit 3d8278a

Please sign in to comment.