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

feat(checkbox, radio, toggle, range): stacked labels for form controls #28075

Merged
merged 14 commits into from
Sep 1, 2023

Conversation

thetaPC
Copy link
Contributor

@thetaPC thetaPC commented Aug 29, 2023

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?

  • Checkbox can stack the label on top of the control and adjust the alignment.
    • New prop align was added with center as the default1
    • New label-placement value was added
    • Snapshots were added
  • Radio can stack the label on top of the control and adjust the alignment.
    • New prop align was added with center as the default1
    • New label-placement value was added
    • Snapshots were added
  • Toggle can stack the label on top of the control and adjust the alignment.
    • New prop align was added with center as the default1
    • New label-placement value was added
    • Snapshots were added
  • Range can stack the label on top of the control and adjust the alignment.
    • New label-placement value was added
    • Alignment cannot be changed. The label will be on the left side when LTR and right when RTL.
    • Snapshots were added, padding was added to the container to prevent the knob from being cut off

Does this introduce a breaking change?

  • Yes
  • No

Other information

Original PR

  • Recommendation: Use the file filter during the PR review to filter out images. It'll make it easier to review code.
  • Associated PR to update ion-docs

Footnotes

  1. center is being used because align-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 when align defaulted to start.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

  2. Screenshot 2023-08-17 at 4 51 36 PM

@github-actions github-actions bot added package: core @ionic/core package package: angular @ionic/angular package package: vue @ionic/vue package labels Aug 29, 2023
@stackblitz
Copy link

stackblitz bot commented Aug 29, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@liamdebeasi liamdebeasi force-pushed the FW-4090-alt branch 2 times, most recently from f60b9ea to 6a4dc5f Compare August 29, 2023 22:40
@thetaPC thetaPC marked this pull request as ready for review August 30, 2023 15:29
Copy link
Contributor

@liamdebeasi liamdebeasi left a 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';
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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.
Copy link
Contributor

@liamdebeasi liamdebeasi Aug 30, 2023

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

Copy link
Contributor

@averyjohnston averyjohnston left a 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.
Copy link
Contributor

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 {
Copy link
Contributor

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).

Copy link
Contributor Author

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.

:host(.range-label-placement-stacked) .range-wrapper {
flex-direction: column;

align-items: normal;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@thetaPC thetaPC merged commit e6c7bb6 into feature-7.4 Sep 1, 2023
43 checks passed
@thetaPC thetaPC deleted the FW-4090-alt branch September 1, 2023 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: angular @ionic/angular package package: core @ionic/core package package: vue @ionic/vue package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants