+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 11 additions & 6 deletions lib/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export function Tabs(props: Props) {

const firstRender = useRef<boolean>(true);
const tabsRef = useRef<HTMLDivElement>(null);
const prevSelectedRef = useRef<Element | null>(null);

const [canScrollLeft, setCanScrollLeft] = useState(false);
const [canScrollRight, setCanScrollRight] = useState(false);

Expand Down Expand Up @@ -64,13 +66,16 @@ export function Tabs(props: Props) {
return;
}

selectedElement.scrollIntoView({
behavior: firstRender.current ? 'auto' : 'smooth',
inline: 'center',
});
firstRender.current = false;
if (prevSelectedRef.current !== selectedElement) {
prevSelectedRef.current = selectedElement;
selectedElement.scrollIntoView({
behavior: firstRender.current ? 'auto' : 'smooth',
inline: 'center',
});
}

tabsElement.addEventListener('wheel', horizontalScroll);
firstRender.current = false;
tabsElement.addEventListener('wheel', horizontalScroll, { passive: true });
tabsElement.addEventListener('scroll', checkScrollable);
window.addEventListener('resize', checkScrollable);
checkScrollable();
Expand Down
15 changes: 9 additions & 6 deletions styles/components/Tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,26 @@
}

.Tabs--scrollable {
--mask-width: 3.25rem;
--mask-width: 3.25em;
--mask-left: 0rem;
--mask-right: 0rem;

display: grid;
padding: 0;

&-content {
overflow: auto;
scrollbar-width: none;
overscroll-behavior: none;
display: flex;
flex-wrap: nowrap;
width: 100%;
padding: var(--space-s) var(--space-s) 0;
mask-image: linear-gradient(
90deg,
transparent calc(var(--mask-left) * 0.5),
transparent calc(var(--mask-left) * 0.66),
black calc(0% + var(--mask-left)),
black calc(100% - var(--mask-right)),
transparent calc(100% - calc(var(--mask-right) * 0.5))
transparent calc(100% - calc(var(--mask-right) * 0.66))
);

&.scrollable-left.scrollable-right {
Expand All @@ -175,8 +178,8 @@
align-content: center;
top: 0;
height: 100%;
margin: none;
border-radius: unset;
margin: 0;
border-radius: 0;
z-index: 1;
}

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载