-
Notifications
You must be signed in to change notification settings - Fork 13.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
feat(checkbox, radio, toggle, range): stacked labels for form controls #28075
Conversation
Run & review this pull request in StackBlitz Codeflow. |
f60b9ea
to
6a4dc5f
Compare
1d5c847
to
25f0229
Compare
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.
The implementation of this is really good! We'll need to choose a different property name than align
since it conflicts with a global deprecated attribute.
Feel free to add me for another review, but once my comments are addressed I think this is good to go.
* `"start"`: The label and control will appear at the top of the container. | ||
* `"center"`: The label and control will appear at the center of the container. | ||
*/ | ||
@Prop() align: 'start' | 'center' = 'center'; |
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're going to need to name this something other than align
because it collides with the global deprecated align
attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. The align
attribute is going to cause the text inside of the label container to be centered.
Maybe we can call this alignment
? Open to other ideas from the team.
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.
You'll also notice that long labels are no longer centered within their container. We're currently discussing the best path forward for this on Slack.
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.
alignment
works for me. And based on the Slack thread, no changes will be needed for centering.
@@ -115,6 +116,13 @@ export class Toggle implements ComponentInterface { | |||
*/ | |||
@Prop() justify: 'start' | 'end' | 'space-between' = 'space-between'; | |||
|
|||
/** | |||
* How to pack the label and control along the cross axis. |
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.
Can we update this comment (and ditto for other components) that this only applies when the label and control are on separate lines such as when using labelPlacement="stacked"
?
@@ -90,8 +90,9 @@ export class Toggle implements ComponentInterface { | |||
* `"start"`: The label will appear to the left of the toggle in LTR and to the right in RTL. | |||
* `"end"`: The label will appear to the right of the toggle in LTR and to the left in RTL. | |||
* `"fixed"`: The label has the same behavior as `"start"` except it also has a fixed width. Long text will be truncated with ellipses ("..."). | |||
* `"stacked"`: The label will appear above the toggle regardless of the direction. The alignment of the label can be controlled with the `align` property. |
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.
Don't forget to update this to reference "alignment" instead of "align" (or whatever name we decide on). Same thing for other components too
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.
LGTM once my comment is addressed 👍
@@ -95,6 +96,13 @@ export class Checkbox implements ComponentInterface { | |||
*/ | |||
@Prop() justify: 'start' | 'end' | 'space-between' = 'space-between'; | |||
|
|||
/** | |||
* How to control the alignment of the checkbox and label on the cross axis. | |||
* `"start"`: The label and control will appear at the top of the container. |
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.
"Top of the container" is a little misleading since it's only true for non-stacked label placements. Maybe something like "start of the cross axis"? Or "left side of the cross axis on LTR, or right side on RTL"? (Ditto for the other components.)
/** | ||
* Label is on top of the checkbox. | ||
*/ | ||
:host(.checkbox-label-placement-stacked) .checkbox-wrapper { |
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.
White space looks strange here (for both the style and the comment block).
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.
Thanks! Lint doesn't seem to catch it.
core/src/components/range/range.scss
Outdated
:host(.range-label-placement-stacked) .range-wrapper { | ||
flex-direction: column; | ||
|
||
align-items: normal; |
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.
Any reason we used align-items: normal
vs. align-items: stretch
here?
Functionally they are the same, but normal
is harder to descern as it changes the value based on the layout mode.
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.
I went with normal
because it's the default value for align-items
. I'll switch it over to prevent any changes based on layout mode.
Issue number: resolves #27229
What is the current behavior?
Checkbox, radio, toggle, and range do not allow labels to be stacked.
What is the new behavior?
align
was added withcenter
as the default1label-placement
value was addedalign
was added withcenter
as the default1label-placement
value was addedalign
was added withcenter
as the default1label-placement
value was addedlabel-placement
value was addedDoes this introduce a breaking change?
Other information
Original PR
ion-docs
Footnotes
center
is being used becausealign-items="center"
was the original style prior to the implementation. Otherwise, the label will not line up correctly on default. For example, the checkbox for iOS will shift the label to the top left corner whenalign
defaulted tostart
.2 This shift happens because the input is larger than the label, making the alignment obvious. But this is not correct, the label must be centered vertically as the default to prevent breaking changes to the current visualizations. ↩ ↩2 ↩3↩