Skip to content

Commit

Permalink
fix(material-experimental/mdc-slider): add strong focus indication (#…
Browse files Browse the repository at this point in the history
…23040)

Fixes that the MDC-based slider didn't have a strong focus indicator.

(cherry picked from commit 32e4bb4)
  • Loading branch information
crisbeto authored and wagnermaciel committed Jul 9, 2021
1 parent 2f90fc2 commit 5a53953
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/material-experimental/mdc-helpers/_focus-indicators.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
// These components have to set `border-radius: 50%` in order to support density scaling
// which will clip a square focus indicator so we have to turn it into a circle.
.mat-mdc-checkbox-ripple.mat-mdc-focus-indicator::before,
.mat-radio-ripple.mat-mdc-focus-indicator::before {
.mat-radio-ripple.mat-mdc-focus-indicator::before,
.mat-mdc-slider .mat-mdc-focus-indicator::before {
border-radius: 50%;
}

Expand All @@ -80,6 +81,9 @@
// For options, render the focus indicator when the class .mat-mdc-option-active is present.
.mat-mdc-focus-indicator.mat-mdc-option-active::before,

// In the MDC slider the focus indicator is inside the thumb.
.mdc-slider__thumb--focused .mat-mdc-focus-indicator::before,

// For all other components, render the focus indicator on focus.
.mat-mdc-focus-indicator:focus::before {
content: '';
Expand Down
5 changes: 4 additions & 1 deletion src/material-experimental/mdc-slider/slider-thumb.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
</div>
</div>
<div class="mdc-slider__thumb-knob" #knob></div>
<div matRipple [matRippleDisabled]="true"></div>
<div
matRipple
class="mat-mdc-focus-indicator"
[matRippleDisabled]="true"></div>
8 changes: 8 additions & 0 deletions src/material-experimental/mdc-slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('MDC-based MatSlider' , () => {
describe('standard range slider', () => {
let sliderInstance: MatSlider;
let startInputInstance: MatSliderThumb;
let sliderElement: HTMLElement;
let endInputInstance: MatSliderThumb;

beforeEach(waitForAsync(() => {
Expand All @@ -119,6 +120,7 @@ describe('MDC-based MatSlider' , () => {
const sliderDebugElement = fixture.debugElement.query(By.directive(MatSlider));
sliderInstance = sliderDebugElement.componentInstance;
startInputInstance = sliderInstance._getInput(Thumb.START);
sliderElement = sliderDebugElement.nativeElement;
endInputInstance = sliderInstance._getInput(Thumb.END);
}));

Expand Down Expand Up @@ -174,6 +176,12 @@ describe('MDC-based MatSlider' , () => {
slideToValue(sliderInstance, 25, Thumb.END, platform.IOS);
expect(startInputInstance.value).toBe(50);
});

it('should have a strong focus indicator in each of the thumbs', () => {
const indicators =
sliderElement.querySelectorAll('.mat-mdc-slider-visual-thumb .mat-mdc-focus-indicator');
expect(indicators.length).toBe(2);
});
});

describe('disabled slider', () => {
Expand Down

0 comments on commit 5a53953

Please sign in to comment.