MCPcopy Create free account
hub / github.com/adobe/react-spectrum / saveScrollPosition

Function saveScrollPosition

packages/dev/s2-docs/src/client.tsx:36–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36function saveScrollPosition() {
37 let scrollContainer = getScrollContainer();
38 let scrollTop = scrollContainer?.scrollTop ?? 0;
39 let windowScrollTop = window.scrollY;
40 let state: HistoryState = {
41 ...(history.state as HistoryState | null),
42 scrollTop,
43 windowScrollTop
44 };
45 history.replaceState(state, '', location.href);
46}
47
48function restoreScrollPosition(state: HistoryState | null) {
49 if (state?.scrollTop != null || state?.windowScrollTop != null) {

Callers 1

navigateFunction · 0.85

Calls 1

getScrollContainerFunction · 0.85

Tested by

no test coverage detected