Skip to content

feat(material/slide-toggle): enabling custom icons through directives #31758

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

uptyler
Copy link

@uptyler uptyler commented Aug 21, 2025

Reasoning:

The M3 specification does not clarify which icons are acceptable to be used within the thumb of the mat-slide-toggle component. Therefore, it would be a benefit to allow developers to customize the thumb icon.

Changes

New Directives

Introduces 4 directives: matCheckedIcon, matUncheckedIcon, matCheckedDisabledIcon, and matUncheckedDisabledIcon These, used in conjuction with <mat-icon>s or svgs will enable custom icons to be injected into the thumb of the slide-toggle as per the m3 spec.
image
image

   <!-- Implementation -->
  <mat-slide-toggle>
    <mat-icon matCheckedIcon>light_mode</mat-icon>
    <mat-icon matUncheckedIcon>dark_mode</mat-icon>
    <mat-icon matCheckedDisabledIcon>lock</mat-icon>
    <mat-icon matUncheckedDisabledIcon>lock_open</mat-icon>
    Custom Icons
  </mat-slide-toggle>

Reworked hideIcon Directive

Reworks hideIcon directive to enable hiding icons based off 4 strings: "both", "checked", "unchecked", and "none".
Casts true and false to "both" and "none" respectively. Casts undefined to "none" and "" to "both".

image image
  <!-- Implementation -->
  <mat-slide-toggle hideIcon="unchecked">No icon (While Unchecked)</mat-slide-toggle>
  <mat-slide-toggle hideIcon="checked">No icon (While Checked)</mat-slide-toggle>
  <mat-slide-toggle hideIcon>No icon</mat-slide-toggle>

Reference:
M3 Spec

Implements #28977

Copy link

google-cla bot commented Aug 21, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Introduces 4 directives: `matCheckedIcon`, `matUncheckedIcon`, `matCheckedDisabledIcon`, and `matUncheckedDisabledIcon`
These, used in conjuction with `<mat-icon>`s or svgs will enable custom icons
to be injected into the thumb of the slide-toggle as per the m3 spec.
Reworks hideIcon directive to enable hiding icons based off 4 strings:
"both", "checked", "unchecked", and "none".
Casts true and false to "both" and "none" respectively.
Casts undefined to "none" and "" to "both".
This is to not break any current functionality.

Implements angular#28977
@uptyler uptyler force-pushed the feature/slide-toggle-icons branch from 122239d to 40222e9 Compare August 21, 2025 21:55
@uptyler uptyler marked this pull request as ready for review August 22, 2025 14:38
@uptyler uptyler requested a review from a team as a code owner August 22, 2025 14:38
@uptyler uptyler requested review from adolgachev and mmalerba and removed request for a team August 22, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant