@@ -127,7 +127,7 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
127
127
private _activeRippleRef : RippleRef | undefined ;
128
128
129
129
/** Whether the slider thumb is currently being pressed. */
130
- private _isActive : boolean = false ;
130
+ readonly _isActive = false ;
131
131
132
132
/** Whether the slider thumb is currently being hovered. */
133
133
private _isHovered : boolean = false ;
@@ -201,14 +201,14 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
201
201
202
202
private _onDragStart ( event : MatSliderDragEvent ) : void {
203
203
if ( event . source . _thumbPosition === this . thumbPosition ) {
204
- this . _isActive = true ;
204
+ ( this as { _isActive : boolean } ) . _isActive = true ;
205
205
this . _showActiveRipple ( ) ;
206
206
}
207
207
}
208
208
209
209
private _onDragEnd ( event : MatSliderDragEvent ) : void {
210
210
if ( event . source . _thumbPosition === this . thumbPosition ) {
211
- this . _isActive = false ;
211
+ ( this as { _isActive : boolean } ) . _isActive = false ;
212
212
this . _activeRippleRef ?. fadeOut ( ) ;
213
213
// Happens when the user starts dragging a thumb, tabs away, and then stops dragging.
214
214
if ( ! this . _sliderInput . _isFocused ( ) ) {
@@ -960,19 +960,31 @@ export class MatSlider
960
960
// observer to ensure that the layout is correct (see #24590 and #25286).
961
961
this . _ngZone . runOutsideAngular ( ( ) => {
962
962
this . _resizeObserver = new ResizeObserver ( entries => {
963
+ // Triggering a layout while the user is dragging can throw off the alignment.
964
+ if ( this . _isActive ( ) ) {
965
+ return ;
966
+ }
967
+
963
968
clearTimeout ( this . _resizeTimer ) ;
964
969
this . _resizeTimer = setTimeout ( ( ) => {
965
970
// The `layout` call is going to call `getBoundingClientRect` to update the dimensions
966
971
// of the host. Since the `ResizeObserver` already calculated them, we can save some
967
972
// work by returning them instead of having to check the DOM again.
968
- this . _cachedHostRect = entries [ 0 ] ?. contentRect ;
969
- this . _layout ( ) ;
970
- this . _cachedHostRect = null ;
973
+ if ( ! this . _isActive ( ) ) {
974
+ this . _cachedHostRect = entries [ 0 ] ?. contentRect ;
975
+ this . _layout ( ) ;
976
+ this . _cachedHostRect = null ;
977
+ }
971
978
} , 50 ) ;
972
979
} ) ;
973
980
this . _resizeObserver . observe ( this . _elementRef . nativeElement ) ;
974
981
} ) ;
975
982
}
983
+
984
+ /** Whether any of the thumbs are currently active. */
985
+ private _isActive ( ) : boolean {
986
+ return this . _getThumb ( Thumb . START ) . _isActive || this . _getThumb ( Thumb . END ) . _isActive ;
987
+ }
976
988
}
977
989
978
990
/** The MDCSliderAdapter implementation. */
0 commit comments