Fixes the scroll to Contact from the price cards

Removing ?pakket= from the URL replaced the click's navigation before the
router scrolled to #contact, and told it not to scroll, so nothing
happened. The clean-up now asks the router to scroll there, below the
fixed header. The review carousel's placeholder is now the longest review
itself, so it matches the carousel's height at every width and no longer
shifts the target while the page scrolls past it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 00:59:20 +02:00
co-authored by Claude Opus 5.5
parent 0fce403ebc
commit 0b00b781b9
7 changed files with 87 additions and 17 deletions
@@ -30,6 +30,8 @@ export default function HomeSection({
aria-labelledby={labelledBy}
data-testid={testId}
bg={tone === 'alt' ? 'paper.alt' : 'paper'}
// An anchor target (#contact) lands below the fixed header
scrollMarginTop={id ? 'header' : undefined}
py={spacing === 'tight' ? 'sectionYTight' : 'sectionY'}
>
<Container maxW={width === 'narrow' ? 'contentNarrow' : 'content'}>
@@ -1,5 +1,5 @@
import { lazy, Suspense, useEffect, useMemo, useState } from 'react';
import { Box } from '@chakra-ui/react';
import { Box, useMediaQuery } from '@chakra-ui/react';
import { useNavigate } from '@tanstack/react-router';
import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage';
import ContactFormGate from '@/components/ContactForm/ContactFormGate';
@@ -72,8 +72,14 @@ export default function ContactSection({
}
}
// Then remove ?pakket= from the address bar (no extra history entry, no
// scroll) and continue keyboard and screen reader users here
// Then remove ?pakket= from the address bar (no extra history entry) and
// continue keyboard and screen reader users here. This navigation
// replaces the "Boek" click's before the router has scrolled for it, so
// it must ask the router to scroll to #contact itself.
const [reducedMotion] = useMediaQuery(
['(prefers-reduced-motion: reduce)'],
{ ssr: false },
);
useEffect(() => {
if (pakket === undefined) return;
void navigate({
@@ -82,9 +88,14 @@ export default function ContactSection({
hash: 'contact',
replace: true,
resetScroll: false,
hashScrollIntoView: false,
hashScrollIntoView: {
behavior: reducedMotion ? 'auto' : 'smooth',
block: 'start',
},
});
document.getElementById(TITLE_ID)?.focus({ preventScroll: true });
// Only when a new ?pakket= arrives, not when the motion setting changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pakket, navigate]);
const subject = mailSubject(chosenName);
@@ -17,16 +17,6 @@ const TestimonialCarousel = lazy(() => import('./TestimonialCarousel'));
const TITLE_ID = 'testimonials-title';
// Keeps about the space of the carousel while it loads, so the page below
// does not jump when it arrives (measured: ±685px on phones, ±790px on
// tablets, ±460px at 1024px, ±625px at 1440px)
const PLACEHOLDER_HEIGHT = {
base: '685px',
md: '790px',
lg: '460px',
xl: '625px',
};
type TestimonialsProps = {
content: HomeContent['testimonials'];
testimonials: Testimonial[];
@@ -61,12 +51,14 @@ export default function Testimonials({
<Box ref={ref}>
{inView ? (
<Suspense
fallback={<Box minH={PLACEHOLDER_HEIGHT} />}
fallback={
<CarouselPlaceholder testimonials={shown} />
}
>
<TestimonialCarousel testimonials={shown} />
</Suspense>
) : (
<Box minH={PLACEHOLDER_HEIGHT} />
<CarouselPlaceholder testimonials={shown} />
)}
</Box>
)}
@@ -74,3 +66,27 @@ export default function Testimonials({
</HomeSection>
);
}
// Stands in for the carousel until it has loaded: the longest review laid
// out exactly like a slide (same padding), plus the controls' height. That
// makes it as tall as the carousel at every screen width, so nothing below
// moves when the carousel takes its place, not even during a scroll to
// #contact that passes this section while it loads.
function CarouselPlaceholder({
testimonials,
}: {
testimonials: Testimonial[];
}) {
const longest = testimonials.reduce((a, b) =>
b.quote.length > a.quote.length ? b : a,
);
return (
<Box>
<Box ps={{ base: 0, sm: '1.5rem' }} pb={{ base: 0, sm: '1.5rem' }}>
<TestimonialSlide testimonial={longest} />
</Box>
{/* The control bar: 48px buttons below the same margin */}
<Box mt="clamp(2.5rem, 5vw, 4rem)" h="48px" />
</Box>
);
}