접근성
This commit is contained in:
@@ -81,22 +81,27 @@ export function Footer() {
|
||||
const mainBanners =
|
||||
bannerList?.filter((banner) => banner.bnrTypeCd === "BNRFTER") ?? [];
|
||||
|
||||
const plugin = useRef(Autoplay({ delay: 2000, stopOnInteraction: true }));
|
||||
// 기본은 정지 상태, 사용자가 시작 버튼을 눌러야 자동 넘김
|
||||
const plugin = useRef(
|
||||
Autoplay({ delay: 2000, stopOnInteraction: true, playOnInit: false }),
|
||||
);
|
||||
const [carouselApi, setCarouselApi] = useState<UseEmblaCarouselType[1]>();
|
||||
const [isAutoplaying, setIsAutoplaying] = useState(true);
|
||||
const [isAutoplaying, setIsAutoplaying] = useState(false);
|
||||
|
||||
// 사용자 조작·초점 진입 등으로 자동 넘김이 멈추거나 재개될 때 버튼 상태를 동기화한다
|
||||
// (autoplay:play/stop 이벤트는 플러그인 내부 상태 변경 "전"에 발생하므로 isPlaying() 대신 이벤트 종류로 판단)
|
||||
useEffect(() => {
|
||||
if (!carouselApi) return;
|
||||
|
||||
const syncAutoplayState = () => setIsAutoplaying(plugin.current.isPlaying());
|
||||
syncAutoplayState();
|
||||
carouselApi.on("autoplay:play", syncAutoplayState);
|
||||
carouselApi.on("autoplay:stop", syncAutoplayState);
|
||||
const handleAutoplayPlay = () => setIsAutoplaying(true);
|
||||
const handleAutoplayStop = () => setIsAutoplaying(false);
|
||||
setIsAutoplaying(plugin.current.isPlaying());
|
||||
carouselApi.on("autoplay:play", handleAutoplayPlay);
|
||||
carouselApi.on("autoplay:stop", handleAutoplayStop);
|
||||
|
||||
return () => {
|
||||
carouselApi.off("autoplay:play", syncAutoplayState);
|
||||
carouselApi.off("autoplay:stop", syncAutoplayState);
|
||||
carouselApi.off("autoplay:play", handleAutoplayPlay);
|
||||
carouselApi.off("autoplay:stop", handleAutoplayStop);
|
||||
};
|
||||
}, [carouselApi]);
|
||||
|
||||
@@ -160,26 +165,11 @@ export function Footer() {
|
||||
>지원센타</a>
|
||||
</div>
|
||||
<div className="hidden sm:block">
|
||||
<div className="mt-4 flex justify-end sm:mt-6">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAutoplayToggle}
|
||||
aria-label={isAutoplaying ? "배너 자동 넘김 멈춤" : "배너 자동 넘김 시작"}
|
||||
className="flex items-center gap-1 rounded-sm border border-border bg-background px-2 py-1 text-sm text-accent-foreground hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||
>
|
||||
{isAutoplaying ? (
|
||||
<Pause className="size-4" aria-hidden="true" />
|
||||
) : (
|
||||
<Play className="size-4" aria-hidden="true" />
|
||||
)}
|
||||
<span>{isAutoplaying ? "멈춤" : "시작"}</span>
|
||||
</button>
|
||||
</div>
|
||||
<Carousel
|
||||
setApi={setCarouselApi}
|
||||
plugins={[plugin.current]}
|
||||
opts={{ loop: true }}
|
||||
className="relative mb-4 mt-2 h-20 sm:mb-8 sm:h-24"
|
||||
className="relative my-4 h-20 sm:my-8 sm:h-24"
|
||||
>
|
||||
<CarouselContent>
|
||||
{mainBanners && mainBanners.length > 0 ? (
|
||||
@@ -206,6 +196,22 @@ export function Footer() {
|
||||
</CarouselItem>
|
||||
)}
|
||||
</CarouselContent>
|
||||
{/* 자동 넘김 정지/시작: 좌측 화살표 앞에 배치 (탭 순서도 화살표보다 먼저) */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAutoplayToggle}
|
||||
title={isAutoplaying ? "배너 자동 넘김 정지" : "배너 자동 넘김 시작"}
|
||||
className="absolute -left-10 top-1/2 z-10 flex h-8 w-8 -translate-y-1/2 items-center justify-center rounded-full border border-input !bg-background text-accent-foreground hover:!bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||
>
|
||||
{isAutoplaying ? (
|
||||
<Pause className="h-4 w-4" aria-hidden="true" />
|
||||
) : (
|
||||
<Play className="h-4 w-4" aria-hidden="true" />
|
||||
)}
|
||||
<span className="sr-only">
|
||||
{isAutoplaying ? "배너 자동 넘김 정지" : "배너 자동 넘김 시작"}
|
||||
</span>
|
||||
</button>
|
||||
<CarouselPrevious className="absolute left-2 top-1/2 z-10 !bg-background text-accent-foreground" />
|
||||
<CarouselNext className="absolute right-2 top-1/2 z-10 !bg-background text-accent-foreground" />
|
||||
</Carousel>
|
||||
|
||||
Reference in New Issue
Block a user