-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit bb3a0e3. # Motivation The animation has been approved by design, so we can keep the current implementation of the auto-hide header as it is. # Changes - Reapply "Hide top on scroll (#589)" # Screenshots More details in original pr -- #589
- Loading branch information
1 parent
617d456
commit c61e663
Showing
9 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
Binary file modified
BIN
-1.16 KB
(99%)
e2e/tooltip.e2e.ts-snapshots/Should-render-tooltip-1-Google-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script lang="ts"> | ||
import { layoutContentTopHidden } from "$lib/stores/layout.store"; | ||
import { onMount } from "svelte"; | ||
// The ScrollSentinel component should be placed right before the content | ||
// inside the scrollable container. | ||
export let scrollContainer: HTMLElement; | ||
// To observe when the top leaves the view | ||
let element: HTMLElement; | ||
onMount(() => { | ||
const observer = new IntersectionObserver( | ||
([entry]) => layoutContentTopHidden.set(!entry.isIntersecting), | ||
{ root: scrollContainer, threshold: 0 }, | ||
); | ||
observer.observe(element); | ||
return () => observer.disconnect(); | ||
}); | ||
</script> | ||
|
||
<div data-tid="sentinel" class="sentinel" bind:this={element}></div> | ||
|
||
<style lang="scss"> | ||
.sentinel { | ||
width: 0; | ||
height: 0; | ||
opacity: 0; | ||
visibility: hidden; | ||
} | ||
</style> |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import ScrollSentinel from "$lib/components/ScrollSentinel.svelte"; | ||
import { layoutContentTopHidden } from "$lib/stores/layout.store"; | ||
import { render } from "@testing-library/svelte"; | ||
import { get } from "svelte/store"; | ||
|
||
describe("ScrollSentinel", () => { | ||
let mockObserverInstance: MockIntersectionObserver; | ||
|
||
class MockIntersectionObserver implements IntersectionObserver { | ||
observe: (target: Element) => void = vi.fn(); | ||
unobserve: (target: Element) => void = vi.fn(); | ||
disconnect: () => void = vi.fn(); | ||
takeRecords: () => IntersectionObserverEntry[] = () => []; | ||
root: Element | Document | null = null; | ||
rootMargin: string = ""; | ||
thresholds: ReadonlyArray<number> = []; | ||
|
||
constructor(private callback: IntersectionObserverCallback) { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
mockObserverInstance = this; | ||
} | ||
|
||
// Simulates IntersectionObserver changes | ||
trigger(entries: Partial<IntersectionObserverEntry>[]) { | ||
this.callback(entries as IntersectionObserverEntry[], this); | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
vi.spyOn(global, "IntersectionObserver").mockImplementation( | ||
(callback) => new MockIntersectionObserver(callback), | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it("should render a sentinel element", () => { | ||
const { container } = render(ScrollSentinel); | ||
expect(container.querySelector("[data-tid='sentinel']")).not.toBeNull(); | ||
}); | ||
|
||
it("should update the store on intersection", () => { | ||
expect(get(layoutContentTopHidden)).toBe(false); | ||
|
||
mockObserverInstance.trigger([{ isIntersecting: false }]); | ||
expect(get(layoutContentTopHidden)).toBe(true); | ||
|
||
mockObserverInstance.trigger([{ isIntersecting: true }]); | ||
expect(get(layoutContentTopHidden)).toBe(false); | ||
}); | ||
}); |