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

[Switch] ref attribute is not the root element #19613

Open
2 tasks done
williamscs opened this issue Feb 8, 2020 · 5 comments
Open
2 tasks done

[Switch] ref attribute is not the root element #19613

williamscs opened this issue Feb 8, 2020 · 5 comments
Labels
breaking change bug 🐛 Something doesn't work component: switch This is the name of the generic UI component, not the React module!

Comments

@williamscs
Copy link

williamscs commented Feb 8, 2020

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When attempting to use the width of a Switch component, I don't get the width of the surrounding span.

Expected Behavior 🤔

When getting the offsetWidth of the Switch's ref, it should be the width of the entire component.

Steps to Reproduce 🕹

Attempt to use the ref component and retrieve the width. Set a component to marginLeft to share that width. (I've also reset the margin).

https://codesandbox.io/s/gifted-joliot-gxzni

Context 🔦

I would expect the helper text to align with the label of the switch (see codesandbox example)

I noticed that the ref was pointing to SpanBase: https://github.com/mui-org/material-ui/blob/7f4b81ffb7b76f73319b38f1b9f287f43c74e6d0/packages/material-ui/src/Switch/Switch.js#L162-L187

Perhaps the ref should be the span and an 'innerRef' would point to the SpanBase? I'm unsure of the right way forward. Maybe I'm misinterpreting what "root" should be, however I would like to get the width of the Switch itself, parent span CSS included.

Your Environment 🌎

Tech Version
Material-UI v4.9.1
React v16.12.0
Browser Chrome
@oliviertassinari oliviertassinari added the component: switch This is the name of the generic UI component, not the React module! label Feb 8, 2020
@oliviertassinari
Copy link
Member

@williamscs Nice catch! I'm not sure it was done deliberately. 8a13bc294e0#diff-8d33bd694cc029cf64dd1749dfc57438R117.
@eps1lon What do you think of moving the ref to the root as a bug fix?

@eps1lon
Copy link
Member

eps1lon commented Feb 9, 2020

@eps1lon What do you think of moving the ref to the root as a bug fix?

And we need to fix our conformance test. The docs we generate from the test don't reflect the behavior correctly.

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work good first issue Great for first contributions. Enable to learn the contribution process. labels Feb 9, 2020
@captain-yossarian
Copy link
Contributor

@williamscs @oliviertassinari @eps1lon if you don't mind I will pick it up

@oliviertassinari oliviertassinari removed bug 🐛 Something doesn't work good first issue Great for first contributions. Enable to learn the contribution process. labels Feb 13, 2020
@oliviertassinari oliviertassinari added this to the v5 milestone Feb 13, 2020
@oliviertassinari oliviertassinari changed the title Switch ref attribute is not the root element [Switch] ref attribute is not the root element Aug 22, 2020
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work breaking change labels May 5, 2021
@oliviertassinari
Copy link
Member

@michaldudak This one might be relevant to your exploration on the unstyled slider.

@michaldudak
Copy link
Member

michaldudak commented Jun 15, 2021

I actually fixed this unknowingly while implementing the Switch using unstyled primitives: #26688.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change bug 🐛 Something doesn't work component: switch This is the name of the generic UI component, not the React module!
Projects
None yet
5 participants