-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[material-ui][Checkbox] Asterisk placement aligned correctly #39721
Conversation
Netlify deploy previewhttps://deploy-preview-39721--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes asterisk placement. There is no need for flex so using Stack is unnecessary.
But div can be used in place of the span as label text and the asterisk is already wrapped in span.
Because using span inside span is not good, the Stack component also uses div.
@axelbostrom I suggest just overriding the diff --git a/packages/mui-material/src/FormControlLabel/FormControlLabel.js b/packages/mui-material/src/FormControlLabel/FormControlLabel.js
index fa0d4cf32c..be38944c23 100644
--- a/packages/mui-material/src/FormControlLabel/FormControlLabel.js
+++ b/packages/mui-material/src/FormControlLabel/FormControlLabel.js
@@ -166,7 +166,7 @@ const FormControlLabel = React.forwardRef(function FormControlLabel(inProps, ref
>
{React.cloneElement(control, controlProps)}
{required ? (
- <Stack direction="row" alignItems="center">
+ <Stack direction="row" alignItems="center" sx={{ display: 'block' }}>
{label}
<AsteriskComponent ownerState={ownerState} aria-hidden className={classes.asterisk}>
 {'*'} |
I don't think there is anything inherently wrong with spans inside spans 🤔 |
@mj12albert Right, but I feel like using stack for the asterisk is very uncessesary, since there is no need for horizontal or vertical aligntment for the asterisk. So yeah either a div or span inside span. I don't think there is an issue with a span inside a span either, but not sure. |
Yes, you are right there is nothing wrong with doing it. It's just less semantic. The span element is a generic inline container for phrasing content, which does not inherently represent anything. It should be used only when no other semantic element is appropriate. |
You are right that is is unnecessary, but to remove it entirely now is a bigger change (that I'd like to avoid) than updating a style |
Just a quick note: Stack was introduced in #37831 to address the asterisk placement issue with different label positions in #37281. Removing it might affect #37281. Edit: I should have added visual regression tests in that PR to explain the purpose of the Stack component. This way, the CI would fail when the Stack component is removed. |
@ZeeshanTamboli ok I will look into this this weekend or on monday. Anyway, what is the best solution using span stack or div? |
Let's keep using the |
This change ensures that the asterisk correctly appears at the end of the label text within the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current changes add unnecessary HTML elements.
Simply this change can work.
- <Stack direction="row" alignItems="center">
- <span>
+ <Stack display="block">
{label}
<AsteriskComponent ownerState={ownerState} aria-hidden className={classes.asterisk}>
 {'*'}
</AsteriskComponent>
- </span>
</Stack>

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should go with @amitabh-sahu's suggestion, it's highly preferable we don't alter the structure to avoid breaking changes
Co-authored-by: Albert Yu <albert@albertyu.co> Signed-off-by: Axel Boström <56017794+axelbostrom@users.noreply.github.com>
Co-authored-by: Albert Yu <albert@albertyu.co> Signed-off-by: Axel Boström <56017794+axelbostrom@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@axelbostrom Looks good ~ thanks for spending the time to work on this ✨
BTW I've added a sandbox to the description and checked out @ZeeshanTamboli's comment: The changes did not break different |
Thanks for the help! Not the most code I have written but a great learning experience :) |
Closes #39626
Demo: https://codesandbox.io/s/https-github-com-mui-material-ui-pull-39721-rdd4kc?file=/src/App.tsx