/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
www/src/utils/handleSmoothScrollToSection.ts
25 строк
737 B
Alex / KATT
chore: simplify ci (#6905)
05 сен 2025, 19:09
Не верифицирован
05 сен 2025, 19:09
a7e35d3
Код
Авторство
О чём код?
const handleSmoothScrollToSection = ( e: React.MouseEvent<HTMLAnchorElement, MouseEvent>, ) => { const isModifiedEvent = !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey); const shouldProcessLinkClick = e.button === 0 && // Ignore everything but left clicks !isModifiedEvent; // Ignore clicks with modifier keys ; if (shouldProcessLinkClick) { e.preventDefault(); const href = e.currentTarget.href; const id = href.split('#')[1]; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const section = document.getElementById(id!); section?.scrollIntoView({ behavior: 'smooth' }); window.history.pushState(null, '', href); } }; export { handleSmoothScrollToSection };