From 5910bd6a04edc7a679ad19766a52d037080fd59a Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Wed, 13 Mar 2019 11:02:41 +0100 Subject: [PATCH 1/3] Fix AutocompleteInput choices are displayed again after selection Fixes #2428 --- cypress/integration/edit.js | 14 ++++++++++++++ .../src/input/AutocompleteInput.js | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/cypress/integration/edit.js b/cypress/integration/edit.js index 01571880ca3..203a93114d8 100644 --- a/cypress/integration/edit.js +++ b/cypress/integration/edit.js @@ -78,6 +78,20 @@ describe('Edit Page', () => { ); }); + it('should allow to select an item from the AutocompleteInput without showing the choices again after', () => { + EditCommentPage.navigate(); + cy.get(EditPostPage.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); + }); + it('should reset the form correctly when switching from edit to create', () => { EditPostPage.navigate(); cy.get(EditPostPage.elements.input('title')).should(el => diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.js b/packages/ra-ui-materialui/src/input/AutocompleteInput.js index d2de222da96..00b9df05471 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.js +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.js @@ -102,6 +102,7 @@ export class AutocompleteInput extends React.Component { suggestions: [], }; + ignoreNextChoicesUpdate = false; inputEl = null; anchorEl = null; @@ -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 From 19e3f1a5a9a4c11e162fae2d681824db628969bd Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Wed, 13 Mar 2019 11:07:55 +0100 Subject: [PATCH 2/3] Better tests --- cypress/integration/edit.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cypress/integration/edit.js b/cypress/integration/edit.js index 203a93114d8..2891cec1b42 100644 --- a/cypress/integration/edit.js +++ b/cypress/integration/edit.js @@ -90,6 +90,15 @@ describe('Edit Page', () => { // 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(EditPostPage.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', () => { From 3c52b8e86533f81be165bffb473824be47a32b63 Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Wed, 13 Mar 2019 13:45:26 +0100 Subject: [PATCH 3/3] Review --- cypress/integration/edit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/integration/edit.js b/cypress/integration/edit.js index 2891cec1b42..29121a5da28 100644 --- a/cypress/integration/edit.js +++ b/cypress/integration/edit.js @@ -80,7 +80,7 @@ describe('Edit Page', () => { it('should allow to select an item from the AutocompleteInput without showing the choices again after', () => { EditCommentPage.navigate(); - cy.get(EditPostPage.elements.input('post_id')).clear().type('Sed quo'); + 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(); @@ -92,7 +92,7 @@ describe('Edit Page', () => { cy.get('[role="tooltip"]').should(el => expect(el).to.not.exist); // Ensure they still appear when needed though - cy.get(EditPostPage.elements.input('post_id')).clear().type('architecto aut'); + 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');