Merged in feat/SW-1953-change-images-keyboard (pull request #2578)

feat(SW-1953): change images with keyboard in image gallery

* feat(SW-1953): change images with keyboard in image gallery


Approved-by: Anton Gunnarsson
Approved-by: Hrishikesh Vaipurkar
This commit is contained in:
Matilda Landström
2025-07-30 12:02:04 +00:00
parent f5531e8238
commit 2c2435af09
2 changed files with 34 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
"use client"
import { AnimatePresence, motion } from "motion/react"
import { useState } from "react"
import { useEffect, useState } from "react"
import { useIntl } from "react-intl"
import { IconButton } from "@scandic-hotels/design-system/IconButton"
@@ -41,6 +41,22 @@ export default function FullView({
onPrev()
}
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === "ArrowLeft") {
handlePrev()
} else if (e.key === "ArrowRight") {
handleNext()
}
}
useEffect(() => {
window.addEventListener("keydown", handleKeyDown)
return () => {
window.removeEventListener("keydown", handleKeyDown)
}
})
const variants = {
initial: (animateLeft: boolean) => ({
opacity: 0,

View File

@@ -1,6 +1,6 @@
"use client"
import { AnimatePresence, motion } from "motion/react"
import { useState } from "react"
import { useEffect, useState } from "react"
import { Button as ButtonRAC } from "react-aria-components"
import { useIntl } from "react-intl"
@@ -48,6 +48,22 @@ export default function Gallery({
onSelectImage(images[prevIndex])
}
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === "ArrowLeft") {
handlePrev()
} else if (e.key === "ArrowRight") {
handleNext()
}
}
useEffect(() => {
window.addEventListener("keydown", handleKeyDown)
return () => {
window.removeEventListener("keydown", handleKeyDown)
}
})
const variants = {
initial: (animateLeft: boolean) => ({
opacity: 0,