Skip to content

fix(material/slider): ensure disabled slider thumb input has 'auto' c… #31311

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 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/material/slider/slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ $fallbacks: m3-slider.get-tokens();
&.mdc-slider--disabled {
cursor: auto;
opacity: 0.38;

.mdc-slider__input {
cursor: auto;
}
}

.mdc-slider__thumb,
Expand Down
16 changes: 16 additions & 0 deletions src/material/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,22 @@ describe('MatSlider', () => {
it('should set the disabled attribute on the input element', () => {
expect(input._hostElement.disabled).toBeTrue();
});

it('should have "auto" cursor on thumb input when slider is disabled', () => {
// The beforeEach already creates a DisabledSlider component fixture and detects changes.
// We can directly access `input` (MatSliderThumb) and its `_hostElement`.
// The slider is disabled by default in this setup.
// fixture.detectChanges() might be needed if there were any dynamic changes
// but here we are checking the initial state of a disabled slider.
// However, calling it ensures the component is stable and styles are applied.
const fixture = TestBed.createComponent(DisabledSlider);
fixture.detectChanges();
const sliderDebugElement = fixture.debugElement.query(By.directive(MatSlider));
const slider = sliderDebugElement.componentInstance;
const inputThumb = slider._getInput(_MatThumb.END) as MatSliderThumb;
const thumbInputElement = inputThumb._hostElement;
expect(getComputedStyle(thumbInputElement).cursor).toBe('auto');
});
});

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