Initial commit: React frontend (SLP Software) + AIDLC workflow docs
Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { MouseEvent } from 'react';
|
||||
|
||||
/**
|
||||
* Smoothly scrolls to the element matching the given in-page anchor (e.g. "#pakketten").
|
||||
*
|
||||
* The app uses hash-based routing (see src/router.tsx) so plain `<a href="#id">` links
|
||||
* would otherwise be intercepted by the router as a path change, which resets the URL
|
||||
* hash back to "/" right after the browser's native anchor scroll. That causes the
|
||||
* "scrolls correctly, then jumps back to top on the next click" behaviour. Intercepting
|
||||
* the click and scrolling manually (without touching the URL hash) avoids the conflict.
|
||||
*/
|
||||
export function scrollToHash(hash: string) {
|
||||
const id = hash.replace(/^#/, '');
|
||||
const target = document.getElementById(id);
|
||||
target?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
/**
|
||||
* Click handler for in-page anchor links. Prevents the default hash navigation
|
||||
* (which would conflict with the app's hash-based router) and scrolls smoothly instead.
|
||||
*/
|
||||
export function handleAnchorClick(event: MouseEvent<HTMLAnchorElement>, href: string) {
|
||||
if (!href.startsWith('#')) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
scrollToHash(href);
|
||||
}
|
||||
Reference in New Issue
Block a user