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(toggle): on/off icons for toggle #25459

Merged
merged 50 commits into from
Jul 6, 2022
Merged

feat(toggle): on/off icons for toggle #25459

merged 50 commits into from
Jul 6, 2022

Conversation

sean-perkins
Copy link
Contributor

@sean-perkins sean-perkins commented Jun 13, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

The Toggle component does not support the accessibility indications for the toggle checked state.

Issue URL: #20524

What is the new behavior?

Introduces the switchLabelsEnabled property to ion-toggle, that developers can use to enable the icon indicators for the toggle's checked state.

For Material Design, the checkbox icon will display when the toggle is checked. When the toggle is unchecked, the minus icon will display.

For iOS, the "I" icon will display when the toggle is checked. When the toggle is unchecked, the "O" icon will display. iOS renders both icons in the DOM, in order to accomplish the pulling effect when the toggle changes state.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev-build: 6.1.10-dev.11655149274.1a5ec2d4

@github-actions github-actions bot added the package: core @ionic/core package label Jun 13, 2022
@sean-perkins sean-perkins marked this pull request as ready for review June 13, 2022 19:36
@sean-perkins sean-perkins requested a review from a team as a code owner June 13, 2022 19:36
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 "-" does not show up in dark mode:
image

Also the checkmark text appears black. We should probably add some screenshot tests for dark mode.

core/src/components/toggle/toggle.tsx Outdated Show resolved Hide resolved
core/src/components/toggle/toggle.tsx Outdated Show resolved Hide resolved
core/src/components/toggle/toggle.tsx Outdated Show resolved Hide resolved
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.

Also the I/O label supposed to appear, not slide in on iOS

native ionic
RPReplay_Final1655153868.MP4
RPReplay_Final1655153898.MP4

Somewhat related, but when dragging the toggle the "O" label overlaps the handle

native ionic
RPReplay_Final1655154138.MP4
RPReplay_Final1655153911.MP4

@sean-perkins
Copy link
Contributor Author

Pushed an update to fix the colors for iOS to align with the spec. This does cause an issue with ion-toggle when color="dark" and the toggle is checked:

Screen Shot 2022-06-13 at 5 26 13 PM

Unsure if we should concern ourself with overriding the text color for this, since it isn't within the iOS spec.

I'll need to do some more discovery into rendering of the icons. Originally when just having the icon flip on iOS (like it does for MD), it made the animation of the knob look choppy. It looks like when the knob is active, I need to set the opacity of the icons to zero (and make sure the icons have a transition for opacity).

@liamdebeasi
Copy link
Contributor

When rendering the on icon over an element with an Ionic color, it might be easiest to use the contrast (ex: var(--ion-color-primary-contrast) color. That should work for both light and dark mode.

For the off text, you might be able to use a step color? The color would change slightly across light vs. dark mode, but I don't know if it really matters (as long as the text is accessible). A benefit of using a stepped color is it is easy for developers to customize on a global level. Full customization is out of scope for this task, but using a stepped color would at least let developers customize the text color without much hassle. (For example, if a developers customized the track color, our default color may not be accessible when used on the new track color)

@sean-perkins
Copy link
Contributor Author

Ok, I think this is finally ready for another review. Was getting burned by trying to nest our SASS mixins:

@include ltr() {
  @include position(x, x, x, x);
}

Instead of just using the positioning values directly and disabling stylelint.

@sean-perkins sean-perkins requested a review from liamdebeasi June 24, 2022 16:43
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 "O" doesn't seem to be centered

image

@@ -99,3 +99,9 @@ $toggle-md-item-end-padding-bottom: 12px !default;

/// @prop - Padding start of the toggle positioned on the end in an item
$toggle-md-item-end-padding-start: $item-md-padding-start !default;

/// @prop - The text color of the on/off labels
$toggle-md-on-off-label-color: #000 !default;
Copy link
Contributor

Choose a reason for hiding this comment

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

How does the color get set for the "O" on iOS mode?

This definitely some scope creep, so feel free to ignore this for now... But what if we had a global css var for this?

For example, tab bar has a default background that can be customized with --ion-tab-bar-background:

$tabbar-md-background: var(--ion-tab-bar-background, $background-color) !default;

Reason why I bring it up is iOS does change the on/off text color when adding high contrast mode.

core/src/components/toggle/toggle.tsx Outdated Show resolved Hide resolved
@sean-perkins
Copy link
Contributor Author

Screen Shot 2022-07-05 at 3 30 48 PM

The "O" label appears to be vertically centered. On iOS it is not horizontal aligned (it appears to be offset further to the left than the right). The screenshot is at 150% zoom.

Your screenshot appears to draw the SVG asset thicker 🤔

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.

Another thought: It might be better to do some more design work around this CSS Variable idea we've been playing with. I'd be fine merging this feature in for now, and then we can figure out the CSS Variable stuff next sprint. Does that work for you? I think this feature is great and pretty much done, so I don't think it makes sense to hold this up on the CSS Variable detail.

@sean-perkins
Copy link
Contributor Author

Yeah I can revert the CSS variable changes and leave them static for now.

@sean-perkins sean-perkins requested a review from liamdebeasi July 6, 2022 02:12
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 "on" label looks great:

image

(Top is native iOS, bottom is Ionic)

The "off" label still is not centered on the x-axis:

image

(Top is native iOS, bottom is Ionic).

Everything else in the PR looks great!

@sean-perkins sean-perkins requested a review from liamdebeasi July 6, 2022 16:30
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.

Much better. Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants