From a50787323f6c230878888c0353f2070186e95c60 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 20 Apr 2020 16:36:08 +0200 Subject: [PATCH] fix(material-experimental/mdc-slide-toggle): strong focus indication not visible (#19048) In #18895 a `border-radius: 50%` was added to the ripple host element of the MDC-based slide toggle in order to support different densities. The problem is that the ripple element is also used to draw a rectangle in strong focus indication mode. These changes move the strong focus indication to the `.mdc-switch__thumb-underlay` and switch the base focus indication to use `::after` instead of `::before`. (cherry picked from commit a2d0418038a7f588e83f97c1e71504afa4a21702) --- .../mdc-slide-toggle/_slide-toggle-theme.scss | 8 ++++---- .../mdc-slide-toggle/slide-toggle.html | 4 ++-- .../mdc-slide-toggle/slide-toggle.scss | 12 +++++++----- .../mdc-slide-toggle/slide-toggle.spec.ts | 7 ++----- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/material-experimental/mdc-slide-toggle/_slide-toggle-theme.scss b/src/material-experimental/mdc-slide-toggle/_slide-toggle-theme.scss index 7e2643d32f55..87780d8da659 100644 --- a/src/material-experimental/mdc-slide-toggle/_slide-toggle-theme.scss +++ b/src/material-experimental/mdc-slide-toggle/_slide-toggle-theme.scss @@ -30,7 +30,7 @@ // MDC's switch doesn't support a `color` property. We add support // for it by adding a CSS class for accent and warn style. .mat-mdc-slide-toggle { - .mdc-switch__thumb-underlay::before, .mat-ripple-element { + .mdc-switch__thumb-underlay::after, .mat-ripple-element { background: $mdc-switch-toggled-off-ripple-color; } @@ -51,18 +51,18 @@ // The ripple color matches the palette only when it's checked. .mat-mdc-slide-toggle-checked { - .mdc-switch__thumb-underlay::before, .mat-ripple-element { + .mdc-switch__thumb-underlay::after, .mat-ripple-element { background: $primary; } &.mat-accent { - .mdc-switch__thumb-underlay::before, .mat-ripple-element { + .mdc-switch__thumb-underlay::after, .mat-ripple-element { background: $accent; } } &.mat-warn { - .mdc-switch__thumb-underlay::before, .mat-ripple-element { + .mdc-switch__thumb-underlay::after, .mat-ripple-element { background: $warn; } } diff --git a/src/material-experimental/mdc-slide-toggle/slide-toggle.html b/src/material-experimental/mdc-slide-toggle/slide-toggle.html index 778e6e02a501..c31607d74227 100644 --- a/src/material-experimental/mdc-slide-toggle/slide-toggle.html +++ b/src/material-experimental/mdc-slide-toggle/slide-toggle.html @@ -2,8 +2,8 @@ [class.mdc-form-field--align-end]="labelPosition == 'before'">
-
-
+
{ }); it('should have a focus indicator', () => { - const slideToggleRippleNativeElement = - slideToggleElement.querySelector('.mat-mdc-slide-toggle-ripple')!; - - expect(slideToggleRippleNativeElement.classList.contains('mat-mdc-focus-indicator')) - .toBe(true); + const underlayElement = slideToggleElement.querySelector('.mdc-switch__thumb-underlay')!; + expect(underlayElement.classList.contains('mat-mdc-focus-indicator')).toBe(true); }); });