-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Fix (slider): Update slider position and ticks when the min and max #1598
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,8 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor { | |
if (!this._isInitialized) { | ||
this.value = this._min; | ||
} | ||
this.snapThumbToValue(); | ||
this._updateTickSeparation(); | ||
} | ||
|
||
@Input() | ||
|
@@ -136,6 +138,8 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor { | |
|
||
set max(v: number) { | ||
this._max = Number(v); | ||
this.snapThumbToValue(); | ||
this._updateTickSeparation(); | ||
} | ||
|
||
@Input() | ||
|
@@ -276,6 +280,9 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor { | |
* is set to something other than a number or 'auto', nothing happens. | ||
*/ | ||
private _updateTickSeparation() { | ||
if (!this._sliderDimensions) { | ||
return; | ||
} | ||
if (this._tickInterval == 'auto') { | ||
this._updateAutoTickSeparation(); | ||
} else if (Number(this._tickInterval)) { | ||
|
@@ -428,8 +435,10 @@ export class SliderRenderer { | |
* Draws ticks onto the tick container. | ||
*/ | ||
drawTicks(tickSeparation: number) { | ||
let sliderTrackContainer = | ||
<HTMLElement>this._sliderElement.querySelector('.md-slider-track-container'); | ||
let tickContainerWidth = sliderTrackContainer.getBoundingClientRect().width; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the size calculation for the tick container change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was checking the width of the same container whose width it was setting. This wasn't a problem before since it never changed after initialization, but now it can change. |
||
let tickContainer = <HTMLElement>this._sliderElement.querySelector('.md-slider-tick-container'); | ||
let tickContainerWidth = tickContainer.getBoundingClientRect().width; | ||
// An extra element for the last tick is needed because the linear gradient cannot be told to | ||
// always draw a tick at the end of the gradient. To get around this, there is a second | ||
// container for ticks that has a single tick mark on the very right edge. | ||
|
@@ -443,10 +452,14 @@ export class SliderRenderer { | |
lastTickContainer.style.background = `linear-gradient(to left, black, black 2px, transparent ` + | ||
`2px, transparent)`; | ||
|
||
// If the second to last tick is too close (a separation of less than half the normal | ||
// separation), don't show it by decreasing the width of the tick container element. | ||
if (tickContainerWidth % tickSeparation < (tickSeparation / 2)) { | ||
// If the second to last tick is too close (a separation of less than half the normal | ||
// separation), don't show it by decreasing the width of the tick container element. | ||
tickContainer.style.width = tickContainerWidth - tickSeparation + 'px'; | ||
} else { | ||
// If there is enough space for the second-to-last tick, restore the default width of the | ||
// tick container. | ||
tickContainer.style.width = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment here like // If there is enough space for the second-to-last tick, restore the default width of the tick container. |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we also need to check that the linear gradient background for the ticks has been updated (since the tick interval will have changed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done