[UBER-129] Fix scroll after collapsing a list header (#3330)

Signed-off-by: Ruslan Bayandinov <wazsone@ya.ru>
This commit is contained in:
Ruslan Bayandinov 2023-06-02 14:07:17 +07:00 committed by GitHub
parent d7400dc03a
commit 10f033ba41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 21 deletions

View File

@ -453,6 +453,14 @@
? 'visible' ? 'visible'
: 'hidden' : 'hidden'
let scrollY: number = 0 let scrollY: number = 0
let safariScrollJumpfix: boolean = true
export const enableSafariScrollJumpFix = (enable: boolean): void => {
if (enable) {
scrollY = divScroll?.scrollTop ?? 0
}
safariScrollJumpfix = enable
}
</script> </script>
<svelte:window on:resize={_resize} /> <svelte:window on:resize={_resize} />
@ -476,24 +484,25 @@
}} }}
class="scroll relative flex-shrink" class="scroll relative flex-shrink"
style:overflow-x={horizontal ? 'auto' : 'hidden'} style:overflow-x={horizontal ? 'auto' : 'hidden'}
on:scroll={(evt) => { on:scroll={() => {
if ($tooltipstore.label !== undefined) closeTooltip() if ($tooltipstore.label !== undefined) closeTooltip()
const newPos = divScroll?.scrollTop ?? 0
// TODO: Workaround: https://front.hc.engineering/workbench/platform/tracker/TSK-760 // TODO: Workaround: https://front.hc.engineering/workbench/platform/tracker/TSK-760
// In Safari scroll could jump on click, with no particular reason. // In Safari scroll could jump on click, with no particular reason.
if (safariScrollJumpfix) {
if ( const newPos = divScroll?.scrollTop ?? 0
!scrolling && if (
!isScrolling && !scrolling &&
scrollY !== 0 && !isScrolling &&
Math.abs(newPos - scrollY) > 100 && scrollY !== 0 &&
divScroll !== undefined && Math.abs(newPos - scrollY) > 100 &&
isSafari() divScroll !== undefined &&
) { isSafari()
divScroll.scrollTop = scrollY ) {
divScroll.scrollTop = scrollY
}
scrollY = divScroll?.scrollTop ?? 0
} }
scrollY = divScroll?.scrollTop ?? 0
}} }}
> >
<div <div

View File

@ -148,6 +148,7 @@
on:select-prev={(evt) => { on:select-prev={(evt) => {
select(-2, evt.detail) select(-2, evt.detail)
}} }}
on:collapsed
/> />
</div> </div>

View File

@ -319,6 +319,7 @@
index: e.detail.index + getInitIndex(categories, i) index: e.detail.index + getInitIndex(categories, i)
}) })
}} }}
on:collapsed
{flatHeaders} {flatHeaders}
{disableHeader} {disableHeader}
{props} {props}

View File

@ -390,6 +390,7 @@
$focusStore = { provider: $focusStore.provider } $focusStore = { provider: $focusStore.provider }
} }
} }
dispatch('collapsed', { div })
} }
localStorage.setItem(categoryCollapseKey, collapsed ? 'true' : 'false') localStorage.setItem(categoryCollapseKey, collapsed ? 'true' : 'false')
}} }}
@ -460,11 +461,6 @@
</div> </div>
<style lang="scss"> <style lang="scss">
.expandCollapse {
overflow: hidden;
transition: height 0.3s ease-out;
height: auto;
}
.zero-container { .zero-container {
border-radius: 0.25rem; border-radius: 0.25rem;

View File

@ -198,7 +198,6 @@
<style lang="scss"> <style lang="scss">
.categoryHeader { .categoryHeader {
position: relative;
position: sticky; position: sticky;
top: 0; top: 0;
padding: 0 2.5rem 0 0.75rem; padding: 0 2.5rem 0 0.75rem;

View File

@ -21,6 +21,7 @@
export let props: Record<string, any> = {} export let props: Record<string, any> = {}
let list: List let list: List
let scroll: Scroller
const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => { const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => {
if (dir === 'vertical') { if (dir === 'vertical') {
@ -42,6 +43,7 @@
<div class="w-full h-full py-4 clear-mins"> <div class="w-full h-full py-4 clear-mins">
<Scroller <Scroller
bind:this={scroll}
fade={{ multipler: { top: 2.75 * viewOptions.groupBy.length, bottom: 0 } }} fade={{ multipler: { top: 2.75 * viewOptions.groupBy.length, bottom: 0 } }}
padding={'0 1rem'} padding={'0 1rem'}
noFade noFade
@ -67,8 +69,13 @@
on:check={(event) => { on:check={(event) => {
listProvider.updateSelection(event.detail.docs, event.detail.value) listProvider.updateSelection(event.detail.docs, event.detail.value)
}} }}
on:content={(evt) => { on:content={(event) => {
listProvider.update(evt.detail) listProvider.update(event.detail)
}}
on:collapsed={(event) => {
scroll.enableSafariScrollJumpFix(false)
event.detail.div.scrollIntoView(true)
scroll.enableSafariScrollJumpFix(true)
}} }}
/> />
</Scroller> </Scroller>