Skip to content

Commit

Permalink
fix: snap to last panel in viewport when navigating up
Browse files Browse the repository at this point in the history
Take the posibility of more than 2 panels in the viewport into account.
  • Loading branch information
guidobouman committed May 3, 2018
1 parent b3e8678 commit 9c00c2a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/panelSnap.js
Expand Up @@ -102,16 +102,12 @@ export default class PanelSnap {

const panelsInViewport = getElementsInContainerViewport(this.container, this.panelList);

switch (panelsInViewport.length) {
case 1:
this.snapToPanel(panelsInViewport[0], delta < 0);
break;
case 2:
this.snapToPanel(panelsInViewport[delta > 0 ? 1 : 0], delta < 0);
break;
default:
throw new Error('PanelSnap could not find a snappable panel, aborting.');
if (panelsInViewport.length === 0) {
throw new Error('PanelSnap could not find a snappable panel, aborting.');
}

const targetIndex = delta > 0 ? panelsInViewport.length - 1 : 0;
this.snapToPanel(panelsInViewport[targetIndex], delta < 0);
}

snapToPanel(panel, toBottom = false) {
Expand Down

0 comments on commit 9c00c2a

Please sign in to comment.