-
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
Add Thumb Label to Slider #976
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ describe('MdSlider', () => { | |
SliderWithValue, | ||
SliderWithStep, | ||
SliderWithAutoTickInterval, | ||
SliderWithSetTickInterval | ||
SliderWithSetTickInterval, | ||
SliderWithThumbLabel, | ||
], | ||
}); | ||
|
||
|
@@ -118,7 +119,7 @@ describe('MdSlider', () => { | |
// offset relative to the track, subtract the offset on the track fill. | ||
let thumbPosition = thumbDimensions.left - trackFillDimensions.left; | ||
// The track fill width should be equal to the thumb's position. | ||
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition)); | ||
expect(trackFillDimensions.width).toBe(thumbPosition); | ||
}); | ||
|
||
it('should update the thumb position on click', () => { | ||
|
@@ -144,7 +145,7 @@ describe('MdSlider', () => { | |
// offset relative to the track, subtract the offset on the track fill. | ||
let thumbPosition = thumbDimensions.left - trackFillDimensions.left; | ||
// The track fill width should be equal to the thumb's position. | ||
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition)); | ||
expect(trackFillDimensions.width).toBe(thumbPosition); | ||
}); | ||
|
||
it('should update the thumb position on slide', () => { | ||
|
@@ -309,7 +310,7 @@ describe('MdSlider', () => { | |
|
||
// The closest snap is halfway on the slider. | ||
expect(thumbDimensions.left).toBe(sliderDimensions.width * 0.5 + sliderDimensions.left); | ||
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition)); | ||
expect(trackFillDimensions.width).toBe(thumbPosition); | ||
}); | ||
|
||
it('should snap the thumb and fill to the nearest value on slide', () => { | ||
|
@@ -325,7 +326,7 @@ describe('MdSlider', () => { | |
|
||
// The closest snap is at the halfway point on the slider. | ||
expect(thumbDimensions.left).toBe(sliderDimensions.left + sliderDimensions.width * 0.5); | ||
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition)); | ||
expect(trackFillDimensions.width).toBe(thumbPosition); | ||
|
||
}); | ||
}); | ||
|
@@ -410,7 +411,7 @@ describe('MdSlider', () => { | |
|
||
// The closest step is at 75% of the slider. | ||
expect(thumbDimensions.left).toBe(sliderDimensions.width * 0.75 + sliderDimensions.left); | ||
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition)); | ||
expect(trackFillDimensions.width).toBe(thumbPosition); | ||
}); | ||
|
||
it('should set the correct step value on slide', () => { | ||
|
@@ -433,7 +434,7 @@ describe('MdSlider', () => { | |
|
||
// The closest snap is at the end of the slider. | ||
expect(thumbDimensions.left).toBe(sliderDimensions.width + sliderDimensions.left); | ||
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition)); | ||
expect(trackFillDimensions.width).toBe(thumbPosition); | ||
}); | ||
}); | ||
|
||
|
@@ -516,6 +517,77 @@ describe('MdSlider', () => { | |
+ 'black 2px, transparent 2px, transparent)'); | ||
}); | ||
}); | ||
|
||
describe('slider with thumb label', () => { | ||
let fixture: ComponentFixture<SliderWithThumbLabel>; | ||
let sliderDebugElement: DebugElement; | ||
let sliderNativeElement: HTMLElement; | ||
let sliderInstance: MdSlider; | ||
let sliderTrackElement: HTMLElement; | ||
let sliderContainerElement: Element; | ||
let thumbLabelTextElement: Element; | ||
|
||
beforeEach(async(() => { | ||
builder.createAsync(SliderWithThumbLabel).then(f => { | ||
fixture = f; | ||
fixture.detectChanges(); | ||
|
||
sliderDebugElement = fixture.debugElement.query(By.directive(MdSlider)); | ||
sliderNativeElement = sliderDebugElement.nativeElement; | ||
sliderInstance = sliderDebugElement.componentInstance; | ||
sliderTrackElement = <HTMLElement>sliderNativeElement.querySelector('.md-slider-track'); | ||
sliderContainerElement = sliderNativeElement.querySelector('.md-slider-container'); | ||
thumbLabelTextElement = sliderNativeElement.querySelector('.md-slider-thumb-label-text'); | ||
}); | ||
})); | ||
|
||
it('should add the thumb label class to the slider container', () => { | ||
expect(sliderContainerElement.classList).toContain('md-slider-thumb-label-showing'); | ||
}); | ||
|
||
it('should update the thumb label text on click', () => { | ||
expect(thumbLabelTextElement.textContent).toBe('0'); | ||
|
||
dispatchClickEvent(sliderTrackElement, 0.13); | ||
fixture.detectChanges(); | ||
|
||
// The thumb label text is set to the slider's value. These should always be the same. | ||
expect(thumbLabelTextElement.textContent).toBe('13'); | ||
}); | ||
|
||
it('should update the thumb label text on slide', () => { | ||
expect(thumbLabelTextElement.textContent).toBe('0'); | ||
|
||
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.56, gestureConfig); | ||
fixture.detectChanges(); | ||
|
||
// The thumb label text is set to the slider's value. These should always be the same. | ||
expect(thumbLabelTextElement.textContent).toBe(`${sliderInstance.value}`); | ||
}); | ||
|
||
it('should show the thumb label on click', () => { | ||
expect(sliderContainerElement.classList).not.toContain('md-slider-active'); | ||
expect(sliderContainerElement.classList).toContain('md-slider-thumb-label-showing'); | ||
|
||
dispatchClickEvent(sliderNativeElement, 0.49); | ||
fixture.detectChanges(); | ||
|
||
// The thumb label appears when the slider is active and the 'md-slider-thumb-label-showing' | ||
// class is applied. | ||
expect(sliderContainerElement.classList).toContain('md-slider-thumb-label-showing'); | ||
expect(sliderContainerElement.classList).toContain('md-slider-active'); | ||
}); | ||
|
||
it('should show the thumb label on slide', () => { | ||
expect(sliderContainerElement.classList).not.toContain('md-slider-active'); | ||
|
||
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.91, gestureConfig); | ||
fixture.detectChanges(); | ||
|
||
expect(sliderContainerElement.classList).toContain('md-slider-thumb-label-showing'); | ||
expect(sliderContainerElement.classList).toContain('md-slider-active'); | ||
}); | ||
}); | ||
}); | ||
|
||
// The transition has to be removed in order to test the updated positions without setTimeout. | ||
|
@@ -572,6 +644,17 @@ class SliderWithAutoTickInterval { } | |
}) | ||
class SliderWithSetTickInterval { } | ||
|
||
@Component({ | ||
template: `<md-slider thumb-label></md-slider>`, | ||
styles: [` | ||
.md-slider-thumb-label, .md-slider-thumb-label-text { | ||
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 for why this is necessary |
||
transition: none !important; | ||
} | ||
`], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
class SliderWithThumbLabel { } | ||
|
||
/** | ||
* Dispatches a click event from an element. | ||
* Note: The mouse event truncates the position for the click. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should probably specify which properties we want to transition. It may not be necessary now, but it can be really annoying to debug if a transition applies to an incompatible property. As was my case with Tooltip a few weeks ago.