Skip to content

Commit bb2fcb3

Browse files
committed
Support infinite scroll
1 parent 12902f9 commit bb2fcb3

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

Diff for: addon/components/ember-scrollable.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,12 @@ export default Component.extend(InboundActionsMixin, DomMixin, {
369369
},
370370

371371
resizeScrollbar() {
372-
this.createScrollbarAndShowIfNecessary();
372+
if (this.get('horizontalScrollbar')) {
373+
this.updateScrollbarAndSetupProperties(this.get('scrollToX'), 'horizontal');
374+
}
375+
if (this.get('verticalScrollbar')) {
376+
this.updateScrollbarAndSetupProperties(this.get('scrollToY'), 'vertical');
377+
}
373378
},
374379

375380
showScrollbar() {

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"ember-cli-sri": "^2.1.0",
4545
"ember-cli-uglify": "^2.0.0",
4646
"ember-code-snippet": "2.0.0",
47+
"ember-composable-helpers": "^2.1.0",
4748
"ember-disable-prototype-extensions": "^1.1.2",
4849
"ember-drag-drop": "0.4.6",
4950
"ember-export-application-global": "^2.0.0",

Diff for: tests/acceptance/index-test.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { module, test } from 'qunit';
22
import { setupApplicationTest } from 'ember-qunit';
3-
import { visit, currentURL } from '@ember/test-helpers';
3+
import { visit, currentURL, triggerEvent as triggerEventTestHelper, settled } from '@ember/test-helpers';
44
import { click, fillIn, find, triggerEvent } from 'ember-native-dom-helpers';
55
import { timeout } from 'ember-scrollable/util/timeout';
66
import { THROTTLE_TIME_LESS_THAN_60_FPS_IN_MS } from 'ember-scrollable/components/ember-scrollable';
@@ -75,4 +75,25 @@ module('Acceptance | ember-scrollbar', function(hooks) {
7575
assert.equal(elementHeight(scrollArea), 18);
7676
assert.ok(find('.no-scrollbar-demo .ember-scrollable .drag-handle:not(.visible)'), 'handle goes away when overflow is gone');
7777
});
78+
79+
test('Scrollbar is resized and correctly positioned during infinite scroll', async function(assert) {
80+
await visit('/');
81+
82+
let dragHandle = await find('.infinite-scroll-demo .drag-handle');
83+
const dragHandleHeightBeforeScroll = parseInt(dragHandle.style.height);
84+
85+
const scrollContent = await find('.infinite-scroll-demo .tse-scroll-content');
86+
// Move scrollbar to bottom
87+
scrollContent.scrollTop =
88+
scrollContent.scrollHeight - scrollContent.offsetHeight;
89+
await triggerEventTestHelper('.tse-scroll-content', 'scroll');
90+
// Wait for scroll event handler adds more scroll content
91+
await settled();
92+
93+
dragHandle = await find('.infinite-scroll-demo .drag-handle');
94+
// Drag handle size should be shorter than before since there is now more scroll content
95+
assert.ok(parseInt(dragHandle.style.height) < dragHandleHeightBeforeScroll);
96+
// Drag handle should not be reset back to the top
97+
assert.ok(parseInt(dragHandle.style.top) !== 0);
98+
});
7899
});

Diff for: tests/dummy/app/controllers/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ import Controller from '@ember/controller';
44

55
export default Controller.extend({
66
isShort: true,
7+
infiniteScrollItems: 20,
8+
infiniteScrollPage: 1,
9+
710
actions: {
811
log(message) {
912
console.log(message);
1013
},
1114
toggleHeight() {
1215
this.toggleProperty('isShort');
16+
},
17+
loadMore() {
18+
const items = ++this.infiniteScrollPage * 20;
19+
console.log(`Load up to ${items} items`);
20+
this.set('infiniteScrollItems', items);
1321
}
1422
}
1523
});

Diff for: tests/dummy/app/templates/index.hbs

+20
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,23 @@
256256
{{code-snippet name="event-and-setter.hbs"}}
257257
</div>
258258
</section>
259+
260+
<section class="infinite-scroll-demo">
261+
<h1>Infinite Scroll</h1>
262+
263+
<div class="output">
264+
{{!-- BEGIN-SNIPPET infinite-scroll --}}
265+
<div style="height: 400px;">
266+
{{#ember-scrollable onScrolledToBottom=(action 'loadMore') as |scrollable|}}
267+
{{#each (repeat (compute scrollable.update infiniteScrollItems)) as |empty|}}
268+
<p>Some Content</p>
269+
{{/each}}
270+
{{/ember-scrollable}}
271+
</div>
272+
{{!-- END-SNIPPET --}}
273+
</div>
274+
275+
<div class="code">
276+
{{code-snippet name="infinite-scroll.hbs"}}
277+
</div>
278+
</section>

0 commit comments

Comments
 (0)