-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(datepicker): popup positioning improvements #4696
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
Merged
tinayuangao
merged 2 commits into
angular:master
from
crisbeto:4631/datepicker-position
May 26, 2017
Merged
Changes from all commits
Commits
Show all changes
2 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -509,6 +509,82 @@ describe('MdDatepicker', () => { | |
.toThrowError(/MdDatepicker: No provider found for .*/); | ||
}); | ||
}); | ||
|
||
describe('popup positioning', () => { | ||
let fixture: ComponentFixture<StandardDatepicker>; | ||
let testComponent: StandardDatepicker; | ||
let input: HTMLElement; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdDatepickerModule, MdInputModule, MdNativeDateModule, NoopAnimationsModule], | ||
declarations: [StandardDatepicker], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(StandardDatepicker); | ||
fixture.detectChanges(); | ||
testComponent = fixture.componentInstance; | ||
input = fixture.debugElement.query(By.css('input')).nativeElement; | ||
input.style.position = 'fixed'; | ||
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. nifty way of testing this, I like it :) |
||
})); | ||
|
||
it('should be below and to the right when there is plenty of space', () => { | ||
input.style.top = input.style.left = '20px'; | ||
testComponent.datepicker.open(); | ||
fixture.detectChanges(); | ||
|
||
const overlayRect = document.querySelector('.cdk-overlay-pane').getBoundingClientRect(); | ||
const inputRect = input.getBoundingClientRect(); | ||
|
||
expect(Math.floor(overlayRect.top)) | ||
.toBe(Math.floor(inputRect.bottom), 'Expected popup to align to input bottom.'); | ||
expect(Math.floor(overlayRect.left)) | ||
.toBe(Math.floor(inputRect.left), 'Expected popup to align to input left.'); | ||
}); | ||
|
||
it('should be above and to the right when there is no space below', () => { | ||
input.style.bottom = input.style.left = '20px'; | ||
testComponent.datepicker.open(); | ||
fixture.detectChanges(); | ||
|
||
const overlayRect = document.querySelector('.cdk-overlay-pane').getBoundingClientRect(); | ||
const inputRect = input.getBoundingClientRect(); | ||
|
||
expect(Math.floor(overlayRect.bottom)) | ||
.toBe(Math.floor(inputRect.top), 'Expected popup to align to input top.'); | ||
expect(Math.floor(overlayRect.left)) | ||
.toBe(Math.floor(inputRect.left), 'Expected popup to align to input left.'); | ||
}); | ||
|
||
it('should be below and to the left when there is no space on the right', () => { | ||
input.style.top = input.style.right = '20px'; | ||
testComponent.datepicker.open(); | ||
fixture.detectChanges(); | ||
|
||
const overlayRect = document.querySelector('.cdk-overlay-pane').getBoundingClientRect(); | ||
const inputRect = input.getBoundingClientRect(); | ||
|
||
expect(Math.floor(overlayRect.top)) | ||
.toBe(Math.floor(inputRect.bottom), 'Expected popup to align to input bottom.'); | ||
expect(Math.floor(overlayRect.right)) | ||
.toBe(Math.floor(inputRect.right), 'Expected popup to align to input right.'); | ||
}); | ||
|
||
it('should be above and to the left when there is no space on the bottom', () => { | ||
input.style.bottom = input.style.right = '20px'; | ||
testComponent.datepicker.open(); | ||
fixture.detectChanges(); | ||
|
||
const overlayRect = document.querySelector('.cdk-overlay-pane').getBoundingClientRect(); | ||
const inputRect = input.getBoundingClientRect(); | ||
|
||
expect(Math.floor(overlayRect.bottom)) | ||
.toBe(Math.floor(inputRect.top), 'Expected popup to align to input top.'); | ||
expect(Math.floor(overlayRect.right)) | ||
.toBe(Math.floor(inputRect.right), 'Expected popup to align to input right.'); | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
|
||
|
This file contains hidden or 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.
why did we switch to
ngSwitch
(I'm fine with it, just curious) is it just a style thing to avoid repeating the condition?Uh oh!
There was an error while loading. Please reload this page.
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.
It's just one less watcher in the template. It'll also be simpler to change if we add more views.