Skip to content

fix(selectOptions): don't select option if select is disabled #344

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

Closed
wants to merge 1 commit into from
Closed

fix(selectOptions): don't select option if select is disabled #344

wants to merge 1 commit into from

Conversation

ben-dyer
Copy link

What: Prevent a select's value from changing with selectOptions if it is disabled

Why: It's possible to change the value of a disabled select using selectOptions. For instance this is passing:

  const {
    container: {firstChild: select},
  } = render(
    <select disabled>
      <option>No value selected</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>,
  )

  expect(select.selectedIndex).toBe(0)

  userEvent.selectOptions(select, '1')
  expect(select.selectedIndex).toBe(1)

How: Exit early in selectOptions if the element is disabled, similar to what is done in clear and upload

Checklist:

  • Documentation N/A
  • Tests
  • Typings N/A
  • Ready to be merged

AFAIK it is ready to be merged, however I am not experienced with this project (only as a user) and there may be very good reasons why this was not already done this way.

Copy link
Member

@nickserv nickserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good so far, but a disabled option should also be ignored similarly

@ben-dyer
Copy link
Author

Thanks for taking a look, I'm happy to expand it a bit to include options. Will update

@kentcdodds
Copy link
Member

You know, it's probably better to just leave this as-is and instead make a pull request to my branch that moves user event into DOM Testing Library: testing-library/dom-testing-library#616

@kentcdodds
Copy link
Member

@all-contributors please add @ben-dyer for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @ben-dyer! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants