Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AutocompleteInput choices are displayed again after selection #2992

Merged
merged 3 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cypress/integration/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ describe('Edit Page', () => {
);
});

it('should allow to select an item from the AutocompleteInput without showing the choices again after', () => {
EditCommentPage.navigate();
cy.get(EditCommentPage.elements.input('post_id')).clear().type('Sed quo');
cy.get('[role="tooltip"]').within(() => {
cy.contains('Accusantium qui nihil voluptatum quia voluptas maxime ab similique');
cy.contains('Sed quo et et fugiat modi').click();
});
cy.get('[role="tooltip"]').should(el => expect(el).to.not.exist);

// Ensure it does not reappear a little after
cy.wait(500);
cy.get('[role="tooltip"]').should(el => expect(el).to.not.exist);

// Ensure they still appear when needed though
cy.get(EditCommentPage.elements.input('post_id')).clear().type('architecto aut');
cy.get('[role="tooltip"]').within(() => {
cy.contains('Sed quo et et fugiat modi');
cy.contains('Sint dignissimos in architecto aut');
cy.contains('A voluptas eius eveniet ut commodi dolor');
});

});

it('should reset the form correctly when switching from edit to create', () => {
EditPostPage.navigate();
cy.get(EditPostPage.elements.input('title')).should(el =>
Expand Down
7 changes: 7 additions & 0 deletions packages/ra-ui-materialui/src/input/AutocompleteInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class AutocompleteInput extends React.Component {
suggestions: [],
};

ignoreNextChoicesUpdate = false;
inputEl = null;
anchorEl = null;

Expand Down Expand Up @@ -136,9 +137,15 @@ export class AutocompleteInput extends React.Component {
: this.props.choices,
prevSuggestions: false,
});
// Avoid displaying the suggestions again when one just has been selected
this.ignoreNextChoicesUpdate = true;
// Ensure to reset the filter
this.updateFilter('');
} else if (!isEqual(choices, this.props.choices)) {
if (this.ignoreNextChoicesUpdate) {
this.ignoreNextChoicesUpdate = false;
return;
}
const selectedItem = this.getSelectedItem(
nextProps,
this.state.inputValue
Expand Down