Skip to content

fix(material/slider): fix internal focus state on safari #28243

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

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/material/slider/slider-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
_onPointerUp(): void {
if (this._isActive) {
this._isActive = false;
if (this._platform.SAFARI) {
this._setIsFocused(false);
}
this.dragEnd.emit({source: this, parent: this._slider, value: this.value});

// This setTimeout is to prevent the pointerup from triggering a value
Expand Down
10 changes: 10 additions & 0 deletions src/material/slider/slider-thumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
OnDestroy,
ViewChild,
ViewEncapsulation,
inject,
} from '@angular/core';
import {MatRipple, RippleAnimationConfig, RippleRef, RippleState} from '@angular/material/core';
import {
Expand All @@ -28,6 +29,7 @@ import {
MAT_SLIDER,
MAT_SLIDER_VISUAL_THUMB,
} from './slider-interface';
import {Platform} from '@angular/cdk/platform';

/**
* The visual slider thumb.
Expand Down Expand Up @@ -96,6 +98,8 @@ export class MatSliderVisualThumb implements _MatSliderVisualThumb, AfterViewIni
/** The host native HTML input element. */
_hostElement: HTMLElement;

private _platform = inject(Platform);

constructor(
readonly _cdr: ChangeDetectorRef,
private readonly _ngZone: NgZone,
Expand Down Expand Up @@ -189,6 +193,12 @@ export class MatSliderVisualThumb implements _MatSliderVisualThumb, AfterViewIni
if (!this._sliderInput._isFocused) {
this._hideRipple(this._focusRippleRef);
}

// On Safari we need to immediately re-show the hover ripple because
// sliders do not retain focus from pointer events on that platform.
if (this._platform.SAFARI) {
this._showHoverRipple();
}
};

/** Handles displaying the hover ripple. */
Expand Down
8 changes: 7 additions & 1 deletion src/material/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,13 @@ describe('MDC-based MatSlider', () => {
pointerdown();
pointerup();
flush();
expect(isRippleVisible('focus')).toBeTrue();

// The slider immediately loses focus on pointerup for Safari.
if (platform.SAFARI) {
expect(isRippleVisible('hover')).toBeTrue();
} else {
expect(isRippleVisible('focus')).toBeTrue();
}
}));

it('should hide the focus ripple on blur', fakeAsync(() => {
Expand Down