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

Migration Issue: ref prop now returns StateManager #3984

Closed
Mhbuur opened this issue Mar 25, 2020 · 4 comments
Closed

Migration Issue: ref prop now returns StateManager #3984

Mhbuur opened this issue Mar 25, 2020 · 4 comments
Labels
issue/reviewed Issue has recently been reviewed (mid-2020)

Comments

@Mhbuur
Copy link

Mhbuur commented Mar 25, 2020

I just upgraded from v2 to v3 - almost painless, except one issue.

With v2 I retrieve a component reference this way (overall context is that I need to blur the control on close):

<Select ref={ref => this._select = ref} ...

With v3 the ref type changed to StateManager and I get the following error:

Type 'StateManager<any, Select>' is not assignable to type 'HTMLInputElement'

I've looked in the migration notes and I can't find anything about this issue. I found a related discussion about ref not being a prop, but none of the suggestions there seem to work (and the issue is still open): #2181

Am I missing the obvious here - how do I get the input element reference in v3?

@bladey bladey added pr/needs-review PRs that need to be reviewed to determine outcome pr/priority PRs that should be addressed sooner rather than later labels May 28, 2020
@bladey bladey removed the pr/priority PRs that should be addressed sooner rather than later label Jun 5, 2020
@bladey bladey added question issue/reviewed Issue has recently been reviewed (mid-2020) and removed pr/needs-review PRs that need to be reviewed to determine outcome labels Jun 12, 2020
@chrisdraws
Copy link

I'm also seeing this issue.

@Rall3n
Copy link
Collaborator

Rall3n commented Aug 6, 2020

ref on the default Select import should always be the StateManager, even in v2. You might have imported the base component directly instead of using the default.

The input responsible for handling blur and focus is available under managerRef.select.inputRef.


But by default you should not have to manage focus or have to trigger blur by default. The StateManager handles this all by its own.

@chrisdraws
Copy link

chrisdraws commented Aug 7, 2020 via email

@bladey bladey added issue/reviewed Issue has recently been reviewed (mid-2020) and removed issue/reviewed Issue has recently been reviewed (mid-2020) labels Aug 24, 2020
@ebonow
Copy link
Collaborator

ebonow commented Dec 9, 2020

@chrisdraws it's currently a known and logged issue that within the scope of onMenuOpen, the menuListRef is null. #4243

The easiest way to get around this is with a timeout to allow the ref to catch up with the state changes.

  const selectRef = useRef();

  const onMenuOpen = () => {
    setTimeout(() => {
      const { menuListRef } = selectRef.current.select;
      // Do stuff with menuListRef
     }, 1);
  };

  return <Select ref={selectRef} onMenuOption={onMenuOption} />

I hope this answers your question. For time being, I will consider this resolved by @Rall3n (Thank you!) and if there are any other questions or concerns, we can re-open this issue. Thanks!

@ebonow ebonow closed this as completed Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/reviewed Issue has recently been reviewed (mid-2020)
Projects
None yet
Development

No branches or pull requests

5 participants