-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(slider): constraints value between min and max #1567
Conversation
@@ -151,7 +151,7 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor { | |||
return; | |||
} | |||
|
|||
this._value = Number(v); | |||
this._value = Math.min(Math.max(Number(v), this.min), this.max); |
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'm thinking that it makes more sense to clamp the rendered position of the thumb than the actual value. Having an invalid value is a state that the control should allow, where the user will likely want to show a validation error.
An easy way to do this would be to have a getRenderedValue
method that did the clamping.
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.
@jelbourn I've created a new patch in this idea.
cc @mmalerba |
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.
Just a few last minor comments
|
||
it('should place the thumb on the min value', () => { | ||
thumbDimensions = thumbElement.getBoundingClientRect(); | ||
expect(thumbDimensions.left).toBe(sliderDimensions.width * 0.0 + sliderDimensions.left); |
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.
This can just be
expect(thumbDimensions.left).toBe(sliderDimensions.left);
|
||
it('should place the thumb on the max value', () => { | ||
thumbDimensions = thumbElement.getBoundingClientRect(); | ||
expect(thumbDimensions.left).toBe(sliderDimensions.width * 1.0 + sliderDimensions.left); |
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.
You should be able to do
expect(thumbDimensions.left).toBe(sliderDimensions.right);
}); | ||
}); | ||
|
||
describe('slider with set min and max and a value between min and max', () => { |
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.
This behavior is already captured by existing unit tests in the "slider with set min and max" section.
styles: [noTransitionStyle], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
class SliderWithValueBetweenMinAndMax { } |
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.
You don't need this component any more.
LGTM, thanks! |
angular#1565) * Set vertical alignment for md-button and md-raised-button so md-icon inside is correctly aligned
@feloy Looks like this just needs another rebase |
… slider-1557 Conflicts: src/lib/slider/slider.spec.ts src/lib/slider/slider.ts
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
Is my rebase ok? I'm not sure if I have to do something about cla:no? |
@feloy something seems to have gone amiss with the rebase; PR is showing 31 commits |
@jelbourn Yes I think I missed my rebase. I can close this PR and create a new one. ok? |
@feloy Fine by me, whatever is easiest for you |
Replaced by #1617 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Should fix #1557