bug(mat-slider): mobile device scrolling can break slider internal state
Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Scrolling on a mobile device can break the mat-slider's internal state such that the slider still thinks it is in an active dragging state when it is not
The root cause of the issue is that for some reason, the pointerup event never gets triggered when the user stops scrolling
Reproduction
- Visit any webpage that has a mat-slider
- Scroll down with the pointerdown originating from the mat-slider
- Stop scrolling
Expected Behavior
The mat-slider is in an inactive state
Actual Behavior
The mat-slider is still in the active state
Environment
- Angular: 17
- CDK/Material: 17
- Browser(s): chrome
- Operating System (e.g. Windows, macOS, Ubuntu): ios
Current workaround for teams is to set touch-action: none on the mat-slider.
Update:
https://github.com/angular/components/pull/28176 does not fix the issue. There is a way to trigger pointercancel but continue dragging the input type="range"
Right now I believe change is the best (only?) event that indicates whether dragging has ended - not pointerup + pointercancel + pointerout + etc.
The problem I'm running into now is: When dragging, arrowing triggers a change event, which is indistinguishable from a change event triggered by pointerup. As far as I can tell, there are only 2 ways to solve for this:
- Diverge from the native
input type="range"behavior and disable arrowing when the user is dragging - Listen for
pointerupandkeydownevents and store which one happens before achangeevent so we can determine whether thechangewas triggered by an arrow key or drag end.
Update:
Listening for change events doesn't work because they are not guaranteed to be the last event that fires. If a user drags a slider thumb but then returns it to its original value, the change event will not fire since the value has not changed.
I discussed this with the team and concluded that the small divergence of setting touch-action: none is ok.