-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 스크린 리더기 focus 개선 #347
Changes from 8 commits
6c5fb78
136e9c3
495abec
1221f26
39247f0
1e93f1c
79f367f
3a7240b
f9710d9
9c278e3
d117d15
a1e2782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import React, { ButtonHTMLAttributes, HTMLAttributes, useRef } from 'react'; | ||
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */ | ||
import React, { ButtonHTMLAttributes, HTMLAttributes, RefObject, useEffect, useRef } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import useDisableBackgroundScroll from './hooks/useDisableBackgroundScroll'; | ||
import useModalEscClose from './hooks/useModalEscClose'; | ||
import { | ||
modalBackdropLayout, | ||
|
@@ -17,18 +17,27 @@ import { | |
} from './Modal.styled'; | ||
|
||
import CloseIcon from '@/assets/images/closeIcon.png'; | ||
import useFocus from '@/hooks/useFocus'; | ||
|
||
export interface ModalProps | ||
extends React.PropsWithChildren<{ | ||
isOpen: boolean; | ||
onClose: () => void; | ||
position?: 'top' | 'bottom' | 'center'; | ||
style?: React.CSSProperties; | ||
closeRef?: RefObject<HTMLElement>; | ||
}> {} | ||
|
||
const Modal = ({ children, isOpen, onClose, position = 'center', ...restProps }: ModalProps) => { | ||
const Modal = ({ | ||
children, | ||
isOpen, | ||
onClose, | ||
closeRef, | ||
position = 'center', | ||
...restProps | ||
}: ModalProps) => { | ||
const modalRef = useRef<HTMLDivElement | null>(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
const focusRef = useFocus<HTMLDivElement>(); | ||
useModalEscClose(isOpen, onClose); | ||
|
||
const handleOutsideClick = (event: React.MouseEvent | React.KeyboardEvent) => { | ||
|
@@ -37,12 +46,26 @@ const Modal = ({ children, isOpen, onClose, position = 'center', ...restProps }: | |
} | ||
}; | ||
|
||
useEffect(() => { | ||
return () => { | ||
if (closeRef?.current) { | ||
closeRef.current.focus(); | ||
} | ||
}; | ||
}, [closeRef?.current]); | ||
|
||
if (!isOpen) return null; | ||
|
||
const modalContent = ( | ||
/* eslint jsx-a11y/no-static-element-interactions: "off" */ | ||
// 모달을 제외한 영역을 클릭시 모달이 꺼지도록 설정하기 위해 설정함 | ||
<div css={modalBackdropLayout} onClick={handleOutsideClick} onKeyDown={handleOutsideClick}> | ||
<div | ||
tabIndex={0} | ||
ref={focusRef} | ||
css={modalBackdropLayout} | ||
onClick={handleOutsideClick} | ||
onKeyDown={handleOutsideClick} | ||
> | ||
<div css={modalContentWrapper({ position })} ref={modalRef} {...restProps}> | ||
{children} | ||
</div> | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */ | ||
import { useRef } from 'react'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
|
@@ -23,6 +25,7 @@ import AlertModal from '@/components/common/AlertModal/AlertModal'; | |
import RoomSettingModal from '@/components/common/RoomSettingModal/RoomSettingModal'; | ||
import { convertMsecToSecond } from '@/components/SelectContainer/Timer/Timer.util'; | ||
import useBalanceContentQuery from '@/hooks/useBalanceContentQuery'; | ||
import useFocus from '@/hooks/useFocus'; | ||
import useModal from '@/hooks/useModal'; | ||
import { memberInfoState } from '@/recoil/atom'; | ||
|
||
|
@@ -63,9 +66,10 @@ export const RoomSettingHeader = ({ title }: HeaderProps) => { | |
const { show } = useModal(); | ||
const { isMaster } = useRecoilValue(memberInfoState); | ||
const { handleExit } = useExit(); | ||
const closeRef = useRef(null); | ||
|
||
const handleClickRoomSetting = () => { | ||
show(RoomSettingModal); | ||
show(RoomSettingModal, { closeRef }); | ||
}; | ||
|
||
const handleClickExit = () => { | ||
|
@@ -79,7 +83,7 @@ export const RoomSettingHeader = ({ title }: HeaderProps) => { | |
</button> | ||
<h1 css={gameTitle}>{title}</h1> | ||
{isMaster ? ( | ||
<button onClick={handleClickRoomSetting} css={buttonWrapper}> | ||
<button ref={closeRef} onClick={handleClickRoomSetting} css={buttonWrapper}> | ||
<img src={SettingIcon} alt="방 설정" css={iconImage} /> | ||
</button> | ||
) : ( | ||
|
@@ -134,13 +138,13 @@ export const GameHeader = () => { | |
// 5. 좌측 상단 뒤로가기, 가운데 제목 차지하는 헤더 (API 호출 X) : 라운드 투표 현황 | ||
export const BackHeader = ({ title }: HeaderProps) => { | ||
const navigate = useNavigate(); | ||
|
||
const focusRef = useFocus<HTMLElement>(); | ||
const goToBack = () => { | ||
navigate(-1); | ||
}; | ||
|
||
return ( | ||
<header css={headerLayout()}> | ||
<header css={headerLayout()} tabIndex={0} ref={focusRef}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 질문 💭tabIndex=0 을 한 이유가 무엇인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<button onClick={goToBack} css={buttonWrapper}> | ||
<img src={ArrowLeft} alt="뒤로 가기" /> | ||
</button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
const useFocus = <T extends HTMLElement>() => { | ||
const focusRef = useRef<T>(null); | ||
|
||
useEffect(() => { | ||
if (focusRef.current) { | ||
focusRef.current.focus(); | ||
} | ||
}, []); | ||
|
||
return focusRef; | ||
}; | ||
|
||
export default useFocus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 질문 💭
Button에는 ref로 적용했는데, Modal에서는 forwardRef를 적용하지 않은 이유가 궁금합니다!