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

fix(dropdown): broken forwardRef binding #7270

Merged
merged 10 commits into from
Dec 8, 2020

Conversation

ConradSchmidt
Copy link
Contributor

Closes #7269

Put ref prop at the end, so that it is not overwritten by other props.

Changelog

New

Changed

  • fixed broken forwardRef for dropdown and multiselect

Removed

Testing / Reviewing

  1. Add ref to dropdown/multiselect
    e.g. in the story:
  const ref = createRef();
  useEffect(() => {
    console.log(ref);
  }, [ref]);
...
<MultiSelect ref={ref} ...
  1. Open console and wait for {current: null}
  2. Apply purposed fix
  3. Open console and wait for current: button#downshift-5-toggle-button.bx--list-box__field}

@netlify
Copy link

netlify bot commented Nov 11, 2020

Deploy preview for carbon-elements ready!

Built with commit f9099a1

https://deploy-preview-7270--carbon-elements.netlify.app

@ConradSchmidt
Copy link
Contributor Author

Is there a reason why the ref is bound to the button? I guess the dropdown (container) itself would be a better candidate.

@netlify
Copy link

netlify bot commented Nov 11, 2020

Deploy preview for carbon-components-react ready!

Built without sensitive environment variables with commit f9099a1

https://deploy-preview-7270--carbon-components-react.netlify.app

@joshblack
Copy link
Contributor

For the ref placement itself it is likely on the button to help with focus management (e.g. a consumer can programmatically focus the button).

Since the getButtonProps helper adds in a ref from downshift, will we need to merge the two refs potentially? 👀

@ConradSchmidt
Copy link
Contributor Author

How should this approach this? Options I see:

  1. leave it like this (I didn't experienced different behaviour)
  2. use the wrapper container (different element) as ref
  3. try to merge refs (no clue how :D)
  4. ?

@joshblack
Copy link
Contributor

Great question @ConradSchmidt! I think you can use the mergeRefs helper that we have: https://github.com/carbon-design-system/carbon/blob/f1c92af3f40585631d8450a4aa381d121dc2c797/packages/react/src/tools/mergeRefs.js

I was trying to dig into that getToggleButtonProps method real quick over on downshift but I couldn't find where it was setting ref. Would you happen to have a link handy? 👀

@ConradSchmidt
Copy link
Contributor Author

@joshblack like this: https://github.com/carbon-design-system/carbon/pull/7270/files#diff-9712440dfce10e10be2619b0921a1ba53e775f5d864aecad652354f4e4d198b1R183?
I can not really verify if this actually works, because even when I overwrite the downshift ref it is working fine. The merging works for the passed in ref, which is a good sign.

@ConradSchmidt
Copy link
Contributor Author

I guess I stop the package installation here, maybe @joshblack can take care of this

@joshblack
Copy link
Contributor

Hey @ConradSchmidt! So sorry about the delay, I pushed up some changes that I think reflect what you were going for, let me know if that works!

@andreancardona
Copy link
Contributor

I still see a failing CI :(

@joshblack
Copy link
Contributor

@andreancardona should be updated now!

@yuecchen
Copy link

yuecchen commented Dec 7, 2020

which version this fix will be go into?

or is there any workaround we can do it overcome this issue?

Copy link
Contributor

@andreancardona andreancardona left a comment

Choose a reason for hiding this comment

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

looks good!

@kodiakhq kodiakhq bot merged commit 6e25954 into carbon-design-system:master Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken forwardRef in Dropdown/Multiselect
5 participants