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

Add a way to clear selection with cy.select() #4318

Closed
flotwig opened this issue May 28, 2019 · 7 comments · Fixed by #18329
Closed

Add a way to clear selection with cy.select() #4318

flotwig opened this issue May 28, 2019 · 7 comments · Fixed by #18329
Assignees
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: enhancement Requested enhancement of existing feature

Comments

@flotwig
Copy link
Contributor

flotwig commented May 28, 2019

This Stack Overflow question points out that cy.select() can't clear a selection, and apparently, neither can commands like cy.clear(): https://stackoverflow.com/questions/56340978/how-do-i-clear-a-select-input-using-cypress

Things that should work, but don't:

  • cy.select([]) should cause no elements to be selected
  • cy.clear() with a <select> subject should cause no elements to be selected

Also, maybe cy.select() or cy.select(undefined) should also clear the selection.

@flotwig flotwig added type: enhancement Requested enhancement of existing feature pkg/driver This is due to an issue in the packages/driver directory good first issue Good for newcomers labels May 28, 2019
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label May 28, 2019
@flotwig flotwig changed the title Add a way to clear selection to cy.select() Add a way to clear selection with cy.select() May 28, 2019
@kylerob
Copy link
Contributor

kylerob commented Oct 1, 2019

@jennifer-shehane I'm willing to work on this for Hacktoberfest. What should we allow as acceptable inputs to clear using the select command? @flotwig I like how clean cy.select() is, but I think cy.select([]) or cy.select(null/undefined) conveys more meaning to readers. Also I'm not sure how much cy.clear() makes sense with selects because according to the docs ".clear() is just an alias for .type({selectall}{backspace})." Taking that action on a dropdown selects the first option (via selectall), and then backspace is a noop. We could look at expanding the scope of clear to make it more than an alias, but starting with changes to select may be good enough.

@flotwig
Copy link
Contributor Author

flotwig commented Oct 1, 2019

Hey @kylerob, thanks for looking at this. To answer your questions:

cy.select([]) and cy.select(null/undefined) should both clear the input field - since cy.select can accept an array of choices, cy.select([]) semantically means "nothing selected". So I'd expect both to work.

Re: cy.clear - you can probably update cy.clear to check the command subject, and if the command subject is a <select>, chain .select([]) on to it; otherwise, do the default behavior (.type({selectall}{backspace}))

cc @bkucera

@kuceb
Copy link
Contributor

kuceb commented Oct 1, 2019

Edit: oh, were talking about multi-value selects. We should accept empty array
you would need to add a test for setting a value to empty array in the spec file here, and edit the select command file: https://github.com/cypress-io/cypress/blob/issue-2957/packages/driver/src/cy/commands/actions/select.coffee

@kylerob
Copy link
Contributor

kylerob commented Oct 1, 2019

@flotwig, @bkucera Thanks for the pointers, I'm starting on it now.

@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress stage: needs review The PR code is done & tested, needs review labels Oct 2, 2019
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs review The PR code is done & tested, needs review labels Dec 18, 2019
@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: work in progress labels Feb 26, 2020
@florenceshelley
Copy link

Hi, is this issue still open and available for grabs?

@signalp
Copy link

signalp commented Apr 3, 2021

Hi, is this issue still open and available for grabs?

Still returning "cy.select() failed because it could not find a single with value or text matching: ``" for me on select multiple (trying .select([]), .select(null), .clear(), all fail)

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: waiting labels Oct 1, 2021
@jennifer-shehane jennifer-shehane added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Oct 11, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 11, 2021

Released in 8.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v8.6.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: enhancement Requested enhancement of existing feature
Projects
None yet
7 participants