Skip to content

4255: Check props to ensure Select not focused when isDisabled changed#4329

Merged
JedWatson merged 4 commits intomasterfrom
Issue-4255--Remove-focus-from-disabled-Select
Jan 13, 2021
Merged

4255: Check props to ensure Select not focused when isDisabled changed#4329
JedWatson merged 4 commits intomasterfrom
Issue-4255--Remove-focus-from-disabled-Select

Conversation

@ebonow
Copy link
Collaborator

@ebonow ebonow commented Dec 12, 2020

Minor Bug Fix for #4255

Expected: When a Select is changed to disabled, it should no longer be focused and the menu should closed (unless specified otherwise by prop menuIsOpen).

Actual: When a Select is changed to disabled, the Control remains styled as if still focused and the state still indicates that the Select is focused. Additionally, the Menu remains open but in a state that is not Selectable.

Example sandbox of behavior:
https://codesandbox.io/s/react-select-4255-focus-while-disabled-7jr14

Solution: Check props on componentDidUpdate for any changes to prop isDisable and resolve discrepancies there.

Notes:

  • This is indeed an edge case as it would be rare to programmatically set a Select to disabled while maintaining focus on the input.
  • This does not resolve issue of phantom options and menu if menuIsOpen is true. While attempting to modify isOptionDisabled by checking props.isDisabled, this method is not called during all state changes and thus does not successfully modify all options as disabled. I left this portion of code out until it would be effective but could be added as such:
  isOptionDisabled(option: OptionType, selectValue: OptionsType): boolean {
    if (props.isDisabled) return true;
    return typeof this.props.isOptionDisabled === 'function'
      ? this.props.isOptionDisabled(option, selectValue)
      : false;
  }
  • Credit for reporting this issue and creating an initial PR to resolve this goes to @arthurakay

@ebonow ebonow added the pr/bug-fix PRs that are specifically addressing a bug label Dec 12, 2020
@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2020

⚠️ No Changeset found

Latest commit: a2971e6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 12, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a2971e6:

Sandbox Source
react-codesandboxer-example Configuration
react-select-4255-focus-while-disabled PR

@lijovijayan
Copy link

Here is a temporary solution for this issue

#762 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/bug-fix PRs that are specifically addressing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants