11import { motion } from "framer-motion" ;
2- import { useState , useEffect } from "react" ;
2+ import { useState , useEffect , useRef } from "react" ;
33import CloseIcon from "@assets/icons/close.svg?react" ;
44import {
55 overlayContainer ,
@@ -28,7 +28,7 @@ interface OnboardingOverlayProps {
2828export const OnboardingOverlay = ( { isShow } : OnboardingOverlayProps ) => {
2929 const [ isVisible , setIsVisible ] = useState ( false ) ;
3030 const [ currentStep , setCurrentStep ] = useState ( 0 ) ;
31-
31+ const overlayRef = useRef < HTMLDivElement > ( null ) ;
3232 const steps : Step [ ] = [
3333 {
3434 target : '[data-onboarding="menu-button"]' ,
@@ -69,7 +69,6 @@ export const OnboardingOverlay = ({ isShow }: OnboardingOverlayProps) => {
6969 ] ;
7070 useEffect ( ( ) => {
7171 const hasCompletedOnboarding = sessionStorage . getItem ( "hasCompletedOnboarding" ) ;
72-
7372 if ( isShow && hasCompletedOnboarding === null ) {
7473 // μμλ€μ΄ λ λλ§λ μκ°μ μ£ΌκΈ° μν΄ μ½κ°μ λλ μ΄ μΆκ°
7574 const timer = setTimeout ( ( ) => {
@@ -80,6 +79,16 @@ export const OnboardingOverlay = ({ isShow }: OnboardingOverlayProps) => {
8079 }
8180 } , [ isShow ] ) ;
8281
82+ useEffect ( ( ) => {
83+ if ( isVisible ) {
84+ const focusTimer = setTimeout ( ( ) => {
85+ overlayRef . current ?. focus ( ) ;
86+ } , 50 ) ;
87+
88+ return ( ) => clearTimeout ( focusTimer ) ;
89+ }
90+ } , [ isVisible ] ) ;
91+
8392 const handleClose = ( ) => {
8493 if ( currentStep < steps . length - 1 ) {
8594 setCurrentStep ( ( prev ) => prev + 1 ) ;
@@ -88,6 +97,11 @@ export const OnboardingOverlay = ({ isShow }: OnboardingOverlayProps) => {
8897 sessionStorage . setItem ( "hasCompletedOnboarding" , "true" ) ;
8998 }
9099 } ;
100+ const handleEnter = ( e : React . KeyboardEvent < HTMLDivElement > ) => {
101+ if ( e . key === "Enter" ) {
102+ handleClose ( ) ;
103+ }
104+ } ;
91105 const handlePrevious = ( ) => {
92106 if ( currentStep > 0 ) {
93107 setCurrentStep ( ( prev ) => prev - 1 ) ;
@@ -145,10 +159,13 @@ export const OnboardingOverlay = ({ isShow }: OnboardingOverlayProps) => {
145159
146160 return (
147161 < motion . div
162+ ref = { overlayRef }
163+ tabIndex = { 0 }
148164 initial = { { opacity : 0 } }
149165 animate = { { opacity : 1 } }
150166 exit = { { opacity : 0 } }
151167 className = { overlayContainer }
168+ onKeyDown = { ( e ) => handleEnter ( e ) }
152169 >
153170 { targetPosition && (
154171 < motion . div
0 commit comments