Skip to content

Commit

Permalink
feat(src/use-tabs): update compute-scroll-into-view
Browse files Browse the repository at this point in the history
  • Loading branch information
megheaiulian committed Apr 9, 2024
1 parent 10d8fb1 commit 54fc425
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/use-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { notifyProperty } from '@neovici/cosmoz-utils/hooks/use-notify-property'
/* eslint-disable-next-line import/no-unresolved */
import { useHashParam, link } from '@neovici/cosmoz-router/use-hash-param';
import { choose, collect, getName, isValid } from './utils';
import compute from 'compute-scroll-into-view';
import { compute } from 'compute-scroll-into-view';

const useTabSelectedEffect = (host, selectedTab) => {
useEffect(() => {
Expand All @@ -19,7 +19,7 @@ const useTabSelectedEffect = (host, selectedTab) => {
const eventOpts = { composed: true };
if (!selectedTab._active) {
selectedTab.dispatchEvent(
new CustomEvent('tab-first-select', eventOpts)
new CustomEvent('tab-first-select', eventOpts),
);
selectedTab._active = true;
}
Expand All @@ -44,7 +44,7 @@ const useTabSelectedEffect = (host, selectedTab) => {
inline: 'center',
boundary: el.parentElement,
}).forEach(({ el, top, left }) =>
el.scroll({ top, left, behavior: 'smooth' })
el.scroll({ top, left, behavior: 'smooth' }),
);
}, [selectedTab]);
},
Expand Down Expand Up @@ -82,15 +82,15 @@ const useTabSelectedEffect = (host, selectedTab) => {

const href = useCallback(
(tab) => (isValid(tab) ? link(hashParam, getName(tab)) : undefined),
[hashParam]
[hashParam],
);

return {
tabs,
selectedTab,
onSlot: useCallback(
({ target }) => requestAnimationFrame(() => setTabs(collect(target))),
[]
[],
),
onSelect: useCallback((e) => {
if (e.button !== 0 || e.metaKey || e.ctrlKey) {
Expand All @@ -106,7 +106,7 @@ const useTabSelectedEffect = (host, selectedTab) => {
e.preventDefault();
window.history.pushState({}, '', href(tab));
requestAnimationFrame(() =>
window.dispatchEvent(new CustomEvent('hashchange'))
window.dispatchEvent(new CustomEvent('hashchange')),
);
}, []),
href,
Expand Down

0 comments on commit 54fc425

Please sign in to comment.