-
Notifications
You must be signed in to change notification settings - Fork 78
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: ensure focused date is visible if overlay is small #809
Changes from all commits
02f2b79
f651090
189fd6d
d1cbf08
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 |
---|---|---|
|
@@ -46,6 +46,19 @@ | |
} | ||
} | ||
|
||
function customizeFixture({initialPosition, monthScrollerItems, monthScrollerOffset}) { | ||
const overlay = fixture('overlay'); | ||
const monthScroller = overlay.$.monthScroller; | ||
monthScroller.style.setProperty('--vaadin-infinite-scroller-buffer-offset', monthScrollerOffset); | ||
monthScroller.updateStyles({'--vaadin-infinite-scroller-buffer-offset': monthScrollerOffset}); | ||
monthScroller.style.height = `${270 * monthScrollerItems}px`; | ||
overlay.i18n = getDefaultI18n(); | ||
overlay.$.monthScroller.bufferSize = 3; | ||
overlay.$.yearScroller.bufferSize = 3; | ||
overlay.initialPosition = initialPosition || new Date(); | ||
return overlay; | ||
} | ||
|
||
describe('vaadin-date-picker-overlay', () => { | ||
var overlay; | ||
|
||
|
@@ -411,54 +424,55 @@ | |
describe('revealDate', () => { | ||
let overlay, monthScroller; | ||
|
||
function fixtureOverlayContent({monthScrollerItems, monthScrollerOffset}, done) { | ||
overlay = fixture('overlay'); | ||
monthScroller = overlay.$.monthScroller; | ||
monthScroller.style.setProperty('--vaadin-infinite-scroller-buffer-offset', monthScrollerOffset); | ||
monthScroller.updateStyles({'--vaadin-infinite-scroller-buffer-offset': monthScrollerOffset}); | ||
monthScroller.style.height = `${270 * monthScrollerItems}px`; | ||
overlay.i18n = getDefaultI18n(); | ||
overlay.$.monthScroller.bufferSize = 3; | ||
overlay.$.yearScroller.bufferSize = 3; | ||
overlay.initialPosition = new Date(2021, 1, 1); | ||
setTimeout(() => { | ||
Polymer.RenderStatus.afterNextRender(overlay, done); | ||
}, 1); | ||
} | ||
|
||
describe('height(visible area) < height(item)', () => { | ||
beforeEach((done) => { | ||
fixtureOverlayContent({ | ||
overlay = customizeFixture({ | ||
initialPosition: new Date(2021, 1, 1), | ||
monthScrollerItems: 0.5, | ||
monthScrollerOffset: 0 | ||
}, done); | ||
}); | ||
|
||
it('should scroll when the month is above the visible area', () => { | ||
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. The old test cases for |
||
const position = monthScroller.position; | ||
}); | ||
monthScroller = overlay.$.monthScroller; | ||
setTimeout(() => { | ||
Polymer.RenderStatus.afterNextRender(overlay, done); | ||
}, 1); | ||
}); | ||
|
||
it('should scroll to a position that approximately shows the week the date is in', () => { | ||
// Starting on first of February | ||
const initialPosition = monthScroller.position; | ||
// Scroll to 15th | ||
overlay.revealDate(new Date(2021, 1, 15), false); | ||
const positionOf15th = monthScroller.position; | ||
expect(positionOf15th).to.be.greaterThan(initialPosition); | ||
expect(positionOf15th).to.be.lessThan(initialPosition + 1); | ||
Comment on lines
+444
to
+447
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. Spent some time to create a test that checks if the date element is actually visible in the scroll area, but could not find a reliable setup. The scroller hard-codes the height of an item to 270px, while the test does not load the theme, which leads to an item only using about 135px. So I went with the same position property checks that the other tests use. |
||
// Scroll to 28th | ||
overlay.revealDate(new Date(2021, 1, 28), false); | ||
const positionOf28th = monthScroller.position; | ||
expect(positionOf28th).to.be.greaterThan(initialPosition); | ||
expect(positionOf28th).to.be.greaterThan(positionOf15th); | ||
expect(positionOf28th).to.be.lessThan(initialPosition + 1); | ||
// Scroll to first of previous month | ||
overlay.revealDate(new Date(2021, 0, 1), false); | ||
expect(monthScroller.position).to.equal(position - 1); | ||
}); | ||
|
||
it('should not scroll when the month is the same', () => { | ||
const position = monthScroller.position; | ||
overlay.revealDate(new Date(2021, 1, 10), false); | ||
expect(monthScroller.position).to.equal(position); | ||
}); | ||
|
||
it('should scroll when the month is below the visible area', () => { | ||
const position = monthScroller.position; | ||
const firstOfPreviousMonthPosition = monthScroller.position; | ||
expect(firstOfPreviousMonthPosition).to.equal(initialPosition - 1); | ||
// Scroll to first of next month | ||
overlay.revealDate(new Date(2021, 2, 1), false); | ||
expect(monthScroller.position).to.equal(position + 1); | ||
const firstOfNextMonthPosition = monthScroller.position; | ||
expect(firstOfNextMonthPosition).to.equal(initialPosition + 1); | ||
}); | ||
}); | ||
|
||
describe('height(visible area) > height(item)', () => { | ||
beforeEach((done) => { | ||
fixtureOverlayContent({ | ||
overlay = customizeFixture({ | ||
initialPosition: new Date(2021, 1, 1), | ||
monthScrollerItems: 2, | ||
monthScrollerOffset: 0 | ||
}, done); | ||
}); | ||
monthScroller = overlay.$.monthScroller; | ||
setTimeout(() => { | ||
Polymer.RenderStatus.afterNextRender(overlay, done); | ||
}, 1); | ||
}); | ||
|
||
it('should scroll when the month is above the visible area', () => { | ||
|
@@ -482,10 +496,15 @@ | |
|
||
describe('offset', () => { | ||
beforeEach((done) => { | ||
fixtureOverlayContent({ | ||
overlay = customizeFixture({ | ||
initialPosition: new Date(2021, 1, 1), | ||
monthScrollerItems: 3, | ||
monthScrollerOffset: '10%' | ||
}, done); | ||
}); | ||
monthScroller = overlay.$.monthScroller; | ||
setTimeout(() => { | ||
Polymer.RenderStatus.afterNextRender(overlay, done); | ||
}, 1); | ||
}); | ||
|
||
it('should scroll when the month is above the visible area', () => { | ||
|
@@ -507,6 +526,81 @@ | |
}); | ||
}); | ||
}); | ||
|
||
describe('scrollToDate', () => { | ||
let overlay, monthScroller; | ||
|
||
describe('height(visible area) < height(item)', () => { | ||
beforeEach((done) => { | ||
overlay = customizeFixture({ | ||
initialPosition: new Date(2021, 1, 1), | ||
monthScrollerItems: 0.5, | ||
monthScrollerOffset: 0 | ||
}); | ||
monthScroller = overlay.$.monthScroller; | ||
setTimeout(() => { | ||
Polymer.RenderStatus.afterNextRender(overlay, done); | ||
}, 1); | ||
}); | ||
|
||
it('should scroll to a sub-month position that approximately shows the week the date is in', () => { | ||
const initialPosition = monthScroller.position; | ||
// Scroll to 15th | ||
overlay.scrollToDate(new Date(2021, 1, 15), false); | ||
const positionOf15th = monthScroller.position; | ||
expect(positionOf15th).to.be.greaterThan(initialPosition); | ||
expect(positionOf15th).to.be.lessThan(initialPosition + 1); | ||
// Scroll to 28th | ||
overlay.scrollToDate(new Date(2021, 1, 28), false); | ||
const positionOf28th = monthScroller.position; | ||
expect(positionOf28th).to.be.greaterThan(initialPosition); | ||
expect(positionOf28th).to.be.greaterThan(positionOf15th); | ||
expect(positionOf28th).to.be.lessThan(initialPosition + 1); | ||
// Scroll to first of previous month | ||
overlay.scrollToDate(new Date(2021, 0, 1), false); | ||
const firstOfPreviousMonthPosition = monthScroller.position; | ||
expect(firstOfPreviousMonthPosition).to.equal(initialPosition - 1); | ||
// Scroll to first of next month | ||
overlay.scrollToDate(new Date(2021, 2, 1), false); | ||
const firstOfNextMonthPosition = monthScroller.position; | ||
expect(firstOfNextMonthPosition).to.equal(initialPosition + 1); | ||
}); | ||
}); | ||
|
||
describe('height(visible area) > height(item)', () => { | ||
beforeEach((done) => { | ||
overlay = customizeFixture({ | ||
initialPosition: new Date(2021, 1, 1), | ||
monthScrollerItems: 3, | ||
monthScrollerOffset: 0 | ||
}); | ||
monthScroller = overlay.$.monthScroller; | ||
setTimeout(() => { | ||
Polymer.RenderStatus.afterNextRender(overlay, done); | ||
}, 1); | ||
}); | ||
|
||
it('should always scroll to the exact position of the month that the date is in', () => { | ||
const initialPosition = monthScroller.position; | ||
// Scroll to 15th | ||
overlay.scrollToDate(new Date(2021, 1, 15), false); | ||
const positionOf15th = monthScroller.position; | ||
expect(positionOf15th).to.equal(initialPosition); | ||
// Scroll to 28th | ||
overlay.scrollToDate(new Date(2021, 1, 28), false); | ||
const positionOf28th = monthScroller.position; | ||
expect(positionOf15th).to.equal(initialPosition); | ||
// Scroll to first of previous month | ||
overlay.scrollToDate(new Date(2021, 0, 1), false); | ||
const firstOfPreviousMonthPosition = monthScroller.position; | ||
expect(firstOfPreviousMonthPosition).to.equal(initialPosition - 1); | ||
// Scroll to first of next month | ||
overlay.scrollToDate(new Date(2021, 2, 1), false); | ||
const firstOfNextMonthPosition = monthScroller.position; | ||
expect(firstOfNextMonthPosition).to.equal(initialPosition + 1); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
|
||
</body> | ||
|
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 covers the initial scrolling to the focused date when opening the overlay.