Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scroll): add top offset when automatically scrolling to main-scroll-item #1277

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<template>
<component :is="tag" v-on="$listeners" :data-scroll="item.id">
<component
:is="tag"
v-on="$listeners"
:data-scroll="item.id"
:style="{ scrollMarginBottom: `-${scrollTopOffset}px` }"
>
<slot />
</component>
</template>
Expand Down Expand Up @@ -46,6 +51,14 @@
@Prop({ default: () => NoElement })
public tag!: string | typeof Vue;

/**
* Top offset when automatically scrolling to this element in pixels.
*
* @public
*/
@Prop({ default: 0 })
public scrollTopOffset!: number;

/**
* Pending identifier scroll position to restore. If it matches the {@link MainScrollItem.item}
* `id` property, this component should be scrolled into view.
Expand Down Expand Up @@ -99,7 +112,9 @@
oldObserver?.unobserve(this.$el);
newObserver?.observe(this.$el);
if (this.pendingScrollTo === this.item.id) {
this.$el.scrollIntoView();
this.$el.scrollIntoView({
block: 'nearest'
});
this.$x.emit('ScrollRestoreSucceeded');
}
}
Expand Down
Loading