JedWatson / JedWatson/react-select

`ref.blur()` leaves broken state if invoked on `onFocus` in `<Creatable />`

Open
#5,305 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-unconfirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Description

There is a onFocus handler in a <Creatable/> component, inside of it we invoke ref.blur().

It blurs the component, but also leaves it in a broken state. The focus ring is still on, and the component is uneditable

const stateMachine = useRef()
return (
  <Creatable
    ref={stateMachine}
    onFocus={() => stateMachine.current.blur()}
  />
)

Reproduction: https://codesandbox.io/s/actual-creatable-6pq682

We "fixed" it by delaying the blur


const stateMachine = useRef()
return (
  <Creatable
    ref={stateMachine}
    onFocus={() => setTimeout(() => stateMachine.current.blur(), 500)}
  />
)

Reproduction: https://codesandbox.io/s/expected-creatable-8m869m

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided actual-creatable CodeSandbox and trace the focus path when its ref.blur() method is called from onFocus. Compare it with the delayed-blur reproduction; done means immediate blur leaves the component editable and removes the focus ring without requiring a timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.