
문제 배경
tab으로 이동 중에 다음 슬라이드의 확대 도구들에 focus가 되어 원치 않는 동작이 발생했습니다.
원인 분석
<Swiper
spaceBetween={10}
slidesPerView={1}
onSlideChange={handleSlideChange}
onSwiper={setSwiperInstance}
initialSlide={initialIndex}
mousewheel={false}
nested={true}
className="h-full w-full"
>
{imageMetadatas.images.map((image) => (
<SwiperSlide key={image.id}>
<div className="w-full h-full flex items-center justify-center">
<TransformViwer
currentImageSrcMetadata={image}
currentIndex={initialIndex}
/>
</div>
</SwiperSlide>
))}
</Swiper>
코드 구조가 swipe를 할 수 있게 swiper 안에 미리 SwiperSlide를 만들어 두는 구조인데 안쪽에 tab-index가 비활성화 되지 않아 있어서 자연스럽게 그곳으로 focus가 옮겨간 것이었습니다.
해결 방안
const ZoomControls = ({
zoomIn,
zoomOut,
resetTransform,
isCurrentImage,
}: ZoomControlsProps) => {
return (
<section
aria-label="이미지 확대/축소 컨트롤"
role="toolbar"
className="flex gap-1 tools absolute bottom-4 right-4 z-10 rounded"
>
<button
type="button"
aria-label="확대"
className="text-white bg-black/60 hover:bg-black/80 focus:bg-black/80 rounded cursor-pointer p-4"
onClick={() => zoomIn()}
tabIndex={isCurrentImage ? 0 : -1}
>
<FiPlus aria-hidden="true" />
</button>
...
</section>
);
};
export default ZoomControls;
isCurrentImage란 props를 만들어 해당 값에 따라
tabIndex={isCurrentImage ? 0 : -1}
tabIndex가 현재 페이지가 아니면 활성화되지 않게 하였습니다.
'개발 > 기록' 카테고리의 다른 글
| zoom & swipe image Viewer: 과도한 음성 텍스트 정리하기 (0) | 2025.03.31 |
|---|---|
| 중고 자동차 사이트 이미지 뷰어 개선 프로젝트: zoom & swipe image Viewer 개발 (1) | 2025.03.27 |
| React JSX에서의 0 처리 특징 (0) | 2025.03.26 |
| zoom & swipe image Viewer: zoom, reset 에러 해결 (0) | 2025.03.25 |
| zoom & swipe image Viewer: 사진 전환 시 zoom 상태 초기화 하기 (0) | 2025.03.23 |