-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
2,497 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export default { | ||
START: 'START', | ||
TOP_FIXED: 'TOP_FIXED', | ||
UNFIXED: 'UNFIXED', | ||
BOTTOM_FIXED: 'BOTTOM_FIXED', | ||
FINISH: 'FINISH' | ||
} | ||
export const START = 'START'; | ||
export const TOP_FIXED = 'TOP_FIXED'; | ||
export const UNFIXED = 'UNFIXED'; | ||
export const BOTTOM_FIXED = 'BOTTOM_FIXED'; | ||
export const FINISH = 'FINISH'; |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function nextFrame() { | ||
return new Promise((resolve) => requestAnimationFrame(resolve)); | ||
} | ||
|
||
export async function scrollTo(top) { | ||
window.scrollTo({ top }); | ||
await nextFrame(); | ||
} | ||
|
||
export function getElementTop(element) { | ||
return element.getBoundingClientRect().top + window.pageYOffset; | ||
} | ||
|
||
export function getElementBottom(element) { | ||
return element.getBoundingClientRect().bottom + window.pageYOffset; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { expect, fixture, html } from '@open-wc/testing'; | ||
import { nextFrame } from './helpers.js'; | ||
import FloatSidebar from '../src/float-sidebar.js'; | ||
|
||
describe('sidebar height', function() { | ||
let wrapperElement, sidebarElement, sidebarInnerElement, contentElement; | ||
let floatSidebar; | ||
|
||
async function forceUpdate() { | ||
floatSidebar.forceUpdate(); | ||
await nextFrame(); | ||
} | ||
|
||
beforeEach(async () => { | ||
wrapperElement = await fixture(html` | ||
<div class="wrapper" style="display: flex; align-items: flex-start;"> | ||
<div class="content" style="flex: 1;"></div> | ||
<div class="sidebar" style="width: 200px; position: relative;"> | ||
<div class="sidebar__inner"></div> | ||
</div> | ||
</div> | ||
`); | ||
contentElement = wrapperElement.querySelector('.content'); | ||
sidebarElement = wrapperElement.querySelector('.sidebar'); | ||
sidebarInnerElement = wrapperElement.querySelector('.sidebar__inner'); | ||
|
||
floatSidebar = new FloatSidebar({ | ||
sidebar: sidebarElement, | ||
relative: contentElement | ||
}); | ||
}); | ||
|
||
describe('height(content) > height(sidebarInner)', () => { | ||
beforeEach(async () => { | ||
contentElement.style.height = '1000px'; | ||
sidebarInnerElement.style.height = '500px'; | ||
await nextFrame(); | ||
}); | ||
|
||
it('should set the sidebar height to the content height', () => { | ||
expect(sidebarElement.style.height).to.equal('1000px'); | ||
}); | ||
|
||
it('should set the sidebar height to the sidebar inner height when it increases', async () => { | ||
sidebarInnerElement.style.height = '2000px'; | ||
await forceUpdate(); | ||
expect(sidebarElement.style.height).to.equal('2000px'); | ||
}); | ||
}); | ||
|
||
describe('height(content) < height(sidebarInner)', () => { | ||
beforeEach(async () => { | ||
contentElement.style.height = '500px'; | ||
sidebarInnerElement.style.height = '1000px'; | ||
await nextFrame(); | ||
}); | ||
|
||
it('should set the sidebar height to the sidebar inner height', () => { | ||
expect(sidebarElement.style.height).to.equal('1000px'); | ||
}); | ||
|
||
it('should set the sidebar height to the content height when it increases', async () => { | ||
contentElement.style.height = '2000px'; | ||
await forceUpdate(); | ||
expect(sidebarElement.style.height).to.equal('2000px'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.