Skip to content

fix(slider): not reacting to directionality changes #6744

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 17 additions & 0 deletions src/lib/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,23 @@ describe('MdSlider without forms', () => {
expect(sliderInstance.value).toBe(30);
});

it('should re-render when the direction changes', () => {
const thumbContainer =
sliderNativeElement.querySelector('.mat-slider-thumb-container')! as HTMLElement;

dispatchClickEventSequence(sliderNativeElement, 0.7);
fixture.detectChanges();

// Some browsers might round the decimals differently.
// Trim the end to normalize the expectation.
expect(thumbContainer.style.transform).toContain('translateX(-30');

testComponent.dir = 'rtl';
fixture.detectChanges();

expect(thumbContainer.style.transform).toContain('translateX(-70');
});

it('should increment inverted slider by 1 on right arrow pressed', () => {
testComponent.invert = true;
fixture.detectChanges();
Expand Down
12 changes: 12 additions & 0 deletions src/lib/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {HammerInput} from '../core';
import {FocusOrigin, FocusOriginMonitor} from '../core/style/focus-origin-monitor';
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled';
import {CanColor, mixinColor} from '../core/common-behaviors/color';
import {Subscription} from 'rxjs/Subscription';


/**
Expand Down Expand Up @@ -276,6 +277,9 @@ export class MdSlider extends _MdSliderMixinBase
*/
_isActive: boolean = false;

/** Subscription to changes in the user's direction. */
private _dirChange: Subscription | undefined;

/**
* Whether the axis of the slider is inverted.
* (i.e. whether moving the thumb in the positive x or y direction decreases the slider's value).
Expand Down Expand Up @@ -413,10 +417,18 @@ export class MdSlider extends _MdSliderMixinBase
this._focusOriginMonitor
.monitor(this._elementRef.nativeElement, renderer, true)
.subscribe((origin: FocusOrigin) => this._isActive = !!origin && origin !== 'keyboard');

if (_dir) {
this._dirChange = _dir.change.subscribe(() => _changeDetectorRef.markForCheck());
}
}

ngOnDestroy() {
this._focusOriginMonitor.stopMonitoring(this._elementRef.nativeElement);

if (this._dirChange) {
this._dirChange.unsubscribe();
}
}

_onMouseenter() {
Expand Down