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

[Radio][Joy] Use precise dimensions for radio icon #35548

Merged
merged 3 commits into from Dec 23, 2022

Conversation

hbjORbj
Copy link
Member

@hbjORbj hbjORbj commented Dec 20, 2022

Closes #35531
Closes #34167

Problem:

  • For variant="outlined", radio icon isn't precisely centered due to the border of radio element.

Solution:

--- a/packages/mui-joy/src/Radio/Radio.tsx
+++ b/packages/mui-joy/src/Radio/Radio.tsx
@@ -204,8 +204,8 @@ const RadioIcon = styled('span', {
   slot: 'Icon',
   overridesResolver: (props, styles) => styles.icon,
 })<{ ownerState: RadioOwnerState }>(({ ownerState }) => ({
-  width: '50%',
-  height: '50%',
+  width: 'calc((var(--Radio-size) - var(--variant-borderWidth)) / 2)',
+  height: 'calc((var(--Radio-size) - var(--variant-borderWidth)) / 2)',

Preview: https://deploy-preview-35548--material-ui.netlify.app/joy-ui/react-radio-button/

P.S. Argos changes are expected.

@hbjORbj hbjORbj self-assigned this Dec 20, 2022
@hbjORbj hbjORbj added component: radio This is the name of the generic UI component, not the React module! design: joy This is about Joy Design, please involve a visual or UX designer in the process bug 🐛 Something doesn't work labels Dec 20, 2022
@mui-bot
Copy link

mui-bot commented Dec 20, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-35548--material-ui.netlify.app/

Details of bundle changes

Generated by 🚫 dangerJS against 928cc0f

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍 Nice catch!

@Studio384
Copy link
Contributor

Studio384 commented Dec 21, 2022

There are still issues with this:

image

This is the "Basic usage" demo from the documentation page in this pull request. The dimensions of the RadioIcon are 9.5x9.5 according to Edge, but it doesn't appear as such. At 100% scaling, these values are rounded to 10 pixels wide and 9 pixels tall.

image

The current height calculation only switches one rounding error out for another.

I'm also not sure why the border is considered like this. The border width only gives the width of a single border and not the border at both sides (horizontal or vertical), so at some point, the border can overlap with the RadioIcon, which I assume its inclusion is trying to prevent in the first place. Adding a * 2 would fix that, but it won't solve this issue of course, because that is just a much more complex way of writing 50%.

@hbjORbj hbjORbj merged commit 94bc99f into mui:master Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: radio This is the name of the generic UI component, not the React module! design: joy This is about Joy Design, please involve a visual or UX designer in the process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Radio][Joy] Button indicator is not centered [Joy] RadioButton selected circle not properly aligned
4 participants