fix(SW-984): Scroll to active card (desktop)

This commit is contained in:
Pontus Dreij
2024-11-25 13:27:19 +01:00
parent 333be1379c
commit 0283c777ca
3 changed files with 25 additions and 8 deletions

View File

@@ -3,4 +3,6 @@
flex-direction: column;
gap: var(--Spacing-x2);
margin-bottom: var(--Spacing-x2);
max-height: 100vh;
overflow-y: auto;
}

View File

@@ -109,13 +109,17 @@ export default function HotelCardListing({
<section className={styles.hotelCards}>
{hotels?.length ? (
hotels.map((hotel) => (
<HotelCard
<div
key={hotel.hotelData.operaId}
hotel={hotel}
type={type}
state={hotel.hotelData.name === activeCard ? "active" : "default"}
onHotelCardHover={onHotelCardHover}
/>
data-active={hotel.hotelData.name === activeCard ? "true" : "false"}
>
<HotelCard
hotel={hotel}
type={type}
state={hotel.hotelData.name === activeCard ? "active" : "default"}
onHotelCardHover={onHotelCardHover}
/>
</div>
))
) : activeFilters ? (
<Alert

View File

@@ -1,7 +1,7 @@
"use client"
import { APIProvider } from "@vis.gl/react-google-maps"
import { useRouter, useSearchParams } from "next/navigation"
import { useEffect, useState } from "react"
import { useEffect, useRef, useState } from "react"
import { useIntl } from "react-intl"
import { useMediaQuery } from "usehooks-ts"
@@ -35,6 +35,7 @@ export default function SelectHotelMap({
const isAboveMobile = useMediaQuery("(min-width: 768px)")
const [activeHotelPin, setActiveHotelPin] = useState<string | null>(null)
const [showBackToTop, setShowBackToTop] = useState<boolean>(false)
const listingContainerRef = useRef<HTMLDivElement | null>(null)
const selectHotelParams = new URLSearchParams(searchParams.toString())
const selectedHotel = selectHotelParams.get("selectedHotel")
@@ -43,6 +44,16 @@ export default function SelectHotelMap({
? cityCoordinates
: { ...cityCoordinates, lat: cityCoordinates.lat - 0.006 }
useEffect(() => {
if (listingContainerRef.current) {
const activeElement =
listingContainerRef.current.querySelector(`[data-active="true"]`)
if (activeElement) {
activeElement.scrollIntoView({ behavior: "smooth", block: "nearest" })
}
}
}, [activeHotelPin])
useEffect(() => {
if (selectedHotel) {
setActiveHotelPin(selectedHotel)
@@ -90,7 +101,7 @@ export default function SelectHotelMap({
return (
<APIProvider apiKey={apiKey}>
<div className={styles.container}>
<div className={styles.listingContainer}>
<div className={styles.listingContainer} ref={listingContainerRef}>
<div className={styles.filterContainer}>
<Button
intent="text"