Skip to content

Commit 92959db

Browse files
feat(yOffset): remove yOffset logic from minimise mode calc
1 parent 1336f0b commit 92959db

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/app/scroll-collapse/scroll-collapse.directive.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,42 @@ describe('ScrollCollapseDirective', () => {
199199
});
200200
expect(directive.affixMode).toBeFalsy();
201201
});
202+
203+
it('should factor in yOffset property when calculating affix mode', () => {
204+
directive.originalHeight = 100;
205+
directive.originalTop = 500;
206+
directive.yOffset = 200;
207+
directive.calculateAffixMode({
208+
scrollX: 0,
209+
scrollY: 0,
210+
width: 1366,
211+
height: 768
212+
});
213+
expect(directive.affixMode).toBeFalsy();
214+
215+
directive.calculateAffixMode({
216+
scrollX: 0,
217+
scrollY: 200,
218+
width: 1366,
219+
height: 768
220+
});
221+
expect(directive.affixMode).toBeFalsy();
222+
223+
directive.calculateAffixMode({
224+
scrollX: 0,
225+
scrollY: 300,
226+
width: 1366,
227+
height: 768
228+
});
229+
expect(directive.affixMode).toBeTruthy();
230+
231+
directive.calculateAffixMode({
232+
scrollX: 0,
233+
scrollY: 299,
234+
width: 1366,
235+
height: 768
236+
});
237+
expect(directive.affixMode).toBeFalsy();
238+
});
202239
});
203240
});

src/app/scroll-collapse/scroll-collapse.directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ScrollCollapseDirective implements AfterViewInit, OnDestroy {
7676
@Input() public debounce = 0;
7777
/**
7878
* Number of pixels before the elements originalTop
79-
* position is scroll to that the classes will be applied.
79+
* position is scroll to that the sn-affix class will be applied.
8080
* This value will need to take into account elements which become
8181
* fixed above this element while scrolling as they reduce
8282
* the height of the document and the scrollY number.
@@ -201,7 +201,7 @@ export class ScrollCollapseDirective implements AfterViewInit, OnDestroy {
201201
*/
202202
public calculateMinimiseMode(viewport: Viewport): void {
203203
this.minimiseMode =
204-
viewport.scrollY >= this.originalHeight + this.originalTop - this.yOffset;
204+
viewport.scrollY >= this.originalHeight + this.originalTop;
205205
}
206206
/**
207207
* Calculate if the user has scrolled pass the origin height of

0 commit comments

Comments
 (0)