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

Selecting multiple options using selectOptions is not working #935

Closed
Thanga-Ganapathy opened this issue Apr 17, 2022 · 5 comments · Fixed by #951
Closed

Selecting multiple options using selectOptions is not working #935

Thanga-Ganapathy opened this issue Apr 17, 2022 · 5 comments · Fixed by #951
Labels
bug Something isn't working released

Comments

@Thanga-Ganapathy
Copy link

Thanga-Ganapathy commented Apr 17, 2022

Reproduction example

https://codesandbox.io/s/pedantic-robinson-cchucu?file=/src/App.js

Prerequisites

  1. Render a form with submit button using the Form component from "@open-tech-world/react-form".
  2. Render a select element using the SelectField from "@open-tech-world/react-form".
  3. Add some options to the select and add multiple attribute.
  4. Select options using userEvent.selectOptions.
  5. Fire click event to the submit button.
  6. Check the form values returned from the Form onSubmit handler.

Expected behavior

The userEvent.selectOptions should select multiple options using the provided string array of the values parameter.

Actual behavior

The userEvent.selectOptions selects only the last option from the given string array of the values parameter, even if the multiple attribute is set.

User-event version

14.1.1

Environment

Testing Library framework: @testing-library/[email protected]

JS framework: [email protected]

Test environment: [email protected]

DOM implementation: @testing-library/[email protected]

Additional context

No response

@Thanga-Ganapathy Thanga-Ganapathy added bug Something isn't working needs assessment This needs to be looked at by a team member labels Apr 17, 2022
@ph-fritsche
Copy link
Member

Thanks for the report.

The [Utility] APIs don't have one-to-one equivalents in a real user interaction.
Their behavior is therefore an interpretation how the "perceived" user interaction might be translated to actual events on the DOM.

The API works on an intrinsic <select> element: https://codesandbox.io/s/red-sun-jmw3hv?file=/src/App.test.js

Someone needs to investigate what exactly throws off the implementation by @open-tech-world/react-form.

@ph-fritsche ph-fritsche added needs investigation Someone has to do research on this and removed needs assessment This needs to be looked at by a team member labels Apr 18, 2022
@Thanga-Ganapathy
Copy link
Author

@ph-fritsche Thanks for the reply.

Yes it is working on the intrinsic elements by default.

Someone needs to investigate what exactly throws off the implementation by @open-tech-world/react-form.

Let me give you some hints about the @open-tech-world/react-form. It internally uses the use-sync-external-store from React to manage the form state.

So, my assumption is that in React concurrent mode, it may skip some state updates when urgent action from the user is expected, and I tried to replicate the same with setTimeout, but I don't know if it is a valid test case. Please ignore it if it's invalid.

Here is the modified intrinsic <select> element: https://codesandbox.io/s/amazing-dawn-lzlzkp?file=/src/App.js

@github-actions
Copy link

🎉 This issue has been resolved in version 14.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ph-fritsche
Copy link
Member

@all-contributors add @Thanga-Ganapathy bug

@allcontributors
Copy link
Contributor

@ph-fritsche

I've put up a pull request to add @Thanga-Ganapathy! 🎉

@ph-fritsche ph-fritsche removed the needs investigation Someone has to do research on this label Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants