-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Comments
@williamscs Nice catch! I'm not sure it was done deliberately. 8a13bc294e0#diff-8d33bd694cc029cf64dd1749dfc57438R117. |
And we need to fix our conformance test. The docs we generate from the test don't reflect the behavior correctly. |
@williamscs @oliviertassinari @eps1lon if you don't mind I will pick it up |
@michaldudak This one might be relevant to your exploration on the unstyled slider. |
I actually fixed this unknowingly while implementing the Switch using unstyled primitives: #26688. |
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 🌎
The text was updated successfully, but these errors were encountered: