[SHOPTIME-3348] My page / Favorites, Recently Viewed Delete 버튼 클릭시 포커싱이 첫번째 item으로 가는 현상

원인 : 기본 포커스를 하단 body 영역으로 설정함.
대책 : delete 모드인 경우, 헤더 영역에 포커스 가도록 수정
This commit is contained in:
yonghyon
2024-10-07 18:17:57 +09:00
parent 95261404ab
commit aa45fe41cd
2 changed files with 37 additions and 76 deletions

View File

@@ -34,15 +34,13 @@ const ContainerBasic = SpotlightContainerDecorator({ enterTo: null }, "div");
export default function Favorites({ title, panelInfo, isOnTop }) { export default function Favorites({ title, panelInfo, isOnTop }) {
const dispatch = useDispatch(); const dispatch = useDispatch();
const favoritesDatas = useSelector( const favoritesDatas = useSelector((state) => state.myPage.favoriteData.favorites);
(state) => state.myPage.favoriteData.favorites const showLoadingPanel = useSelector((state) => state.common.appStatus.showLoadingPanel);
);
const favoriteRetCode = useSelector((state) => state.myPage.favoriteRetCode);
const [activeDelete, setActiveDelete] = useState(false); const [activeDelete, setActiveDelete] = useState(false);
const [selectedItems, setSelectedItems] = useState({}); const [selectedItems, setSelectedItems] = useState({});
const [selectAll, setSelectAll] = useState(false); const [selectAll, setSelectAll] = useState(false);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const spotRestoredRef = useRef(false);
let timerRef = useRef(); let timerRef = useRef();
@@ -50,15 +48,18 @@ export default function Favorites({ title, panelInfo, isOnTop }) {
const focusedContainerIdRef = useRef(null); const focusedContainerIdRef = useRef(null);
useEffect(() => { useEffect(() => {
if (isOnTop) { if (isOnTop && !loading) {
timerRef.current = setTimeout(() => { setTimeout(() => {
if ( if (activeDelete) {
panelInfo.currentSpot && Spotlight.focus("favorites_header");
document.querySelector( return;
`[data-spotlight-id="${panelInfo.currentSpot}"]` }
) let ret = null;
) { if (!spotRestoredRef.current && panelInfo.currentSpot) {
Spotlight.focus(panelInfo.currentSpot); ret = Spotlight.focus(panelInfo.currentSpot);
}
if (ret) {
spotRestoredRef.current = true;
} else { } else {
if (favoritesDatas && favoritesDatas.length > 0) { if (favoritesDatas && favoritesDatas.length > 0) {
Spotlight.focus(SpotlightIds.MY_PAGE_FAVORITES_BOX); Spotlight.focus(SpotlightIds.MY_PAGE_FAVORITES_BOX);
@@ -68,36 +69,17 @@ export default function Favorites({ title, panelInfo, isOnTop }) {
} }
}, 0); }, 0);
} }
}, [isOnTop, panelInfo, favoritesDatas]); }, [isOnTop, loading, panelInfo, favoritesDatas]);
useEffect(() => { useEffect(() => {
if (favoritesDatas) { clearTimeout(timerRef.current);
if (favoritesDatas.length === 0) { timerRef.current = setTimeout(() => {
timerRef.current = setTimeout( setLoading(showLoadingPanel.show);
() => Spotlight.focus("mypage-favorites-nodata"), }, 100);
0 }, [dispatch, showLoadingPanel]);
);
}
if (favoriteRetCode === 0) {
setLoading(false);
if (!panelInfo.currentSpot) {
timerRef.current = setTimeout(
() => Spotlight.focus(SpotlightIds.MY_PAGE_FAVORITES_BOX),
0
);
}
}
}
}, [dispatch, favoritesDatas, favoriteRetCode, loading, panelInfo]);
useEffect(() => { useEffect(() => {
dispatch(getMyFavorite()); dispatch(getMyFavorite());
if (!panelInfo?.currentSpot) {
clearFavorites();
}
}, [dispatch, panelInfo]); }, [dispatch, panelInfo]);
useEffect(() => { useEffect(() => {
@@ -157,20 +139,8 @@ export default function Favorites({ title, panelInfo, isOnTop }) {
})); }));
} }
} }
setActiveDelete((prev) => !prev); setActiveDelete((prev) => !prev);
if (favoritesDatas) { }, [dispatch, favoritesDatas, selectedItems, activeDelete]);
timerRef.current = setTimeout(
() => Spotlight.focus(SpotlightIds.MY_PAGE_FAVORITES_BOX),
0
);
}
}, [
dispatch,
favoritesDatas,
selectedItems,
activeDelete,
]);
const handleSelectAllToggle = useCallback(() => { const handleSelectAllToggle = useCallback(() => {
const newState = !selectAll; const newState = !selectAll;
@@ -192,7 +162,9 @@ export default function Favorites({ title, panelInfo, isOnTop }) {
const handleCancelButtonClick = useCallback(() => { const handleCancelButtonClick = useCallback(() => {
setActiveDelete(false); setActiveDelete(false);
setTimeout(() => {
Spotlight.focus("favorites_header");
}, 0);
const initialSelectedItems = favoritesDatas?.reduce((acc, item) => { const initialSelectedItems = favoritesDatas?.reduce((acc, item) => {
acc[item.prdtId] = false; acc[item.prdtId] = false;
return acc; return acc;
@@ -200,13 +172,6 @@ export default function Favorites({ title, panelInfo, isOnTop }) {
setSelectedItems(initialSelectedItems); setSelectedItems(initialSelectedItems);
setSelectAll(false); setSelectAll(false);
if (favoritesDatas) {
timerRef.current = setTimeout(
() => Spotlight.focus(SpotlightIds.MY_PAGE_FAVORITES_BOX),
0
);
}
}, [favoritesDatas, activeDelete]); }, [favoritesDatas, activeDelete]);
const handleItemClick = useCallback( const handleItemClick = useCallback(
@@ -256,6 +221,7 @@ export default function Favorites({ title, panelInfo, isOnTop }) {
return ( return (
<> <>
<THeader <THeader
spotlightId="favorites_header"
title={title} title={title}
className={css.favoritesHeader} className={css.favoritesHeader}
ariaLabel="FAVORITE, heading 1" ariaLabel="FAVORITE, heading 1"

View File

@@ -58,24 +58,20 @@ export default function RecentlyViewed({ title, panelInfo, isOnTop }) {
const { httpHeader } = useSelector((state) => state.common); const { httpHeader } = useSelector((state) => state.common);
let timerRef = useRef();
useEffect(() => { useEffect(() => {
if (recentlyDatas.length === 0) {
timerRef.current = setTimeout(
() => Spotlight.focus("mypage-recentlyViewed-nodata"),
0
);
}
if (recentlyDatas) { if (recentlyDatas) {
timerRef.current = setTimeout(() => { setTimeout(() => {
const node = document.querySelector(`[id="${SpotlightIds.TBODY}"]`); const node = document.querySelector(`[id="${SpotlightIds.TBODY}"]`);
if (node) { if (activeDelete) {
Spotlight.focus("recentlyviewed_header");
} else if (recentlyDatas.length === 0) {
Spotlight.focus("mypage-recentlyViewed-nodata");
} else if (node) {
Spotlight.focus(node); Spotlight.focus(node);
} }
}, 0); }, 0);
} }
}, [recentlyDatas, activeDelete]); }, [recentlyDatas]);
useEffect(() => { useEffect(() => {
if (panelInfo) { if (panelInfo) {
@@ -86,10 +82,6 @@ export default function RecentlyViewed({ title, panelInfo, isOnTop }) {
} }
}, [panelInfo]); }, [panelInfo]);
useEffect(() => {
return () => timerRef.current && clearTimeout(timerRef.current);
}, []);
useEffect(() => { useEffect(() => {
// selectedItems 초기화 작업 // selectedItems 초기화 작업
const initialSelectedItems = recentlyDatas?.reduce((acc, currVal) => { const initialSelectedItems = recentlyDatas?.reduce((acc, currVal) => {
@@ -197,7 +189,9 @@ export default function RecentlyViewed({ title, panelInfo, isOnTop }) {
const handleCancelButtonClick = useCallback(() => { const handleCancelButtonClick = useCallback(() => {
setActiveDelete(false); setActiveDelete(false);
setTimeout(() => {
Spotlight.focus("recentlyviewed_header");
}, 0);
const initialSelectedItems = recentlyDatas?.reduce((acc, currVal) => { const initialSelectedItems = recentlyDatas?.reduce((acc, currVal) => {
currVal.productInfos.map((item) => { currVal.productInfos.map((item) => {
acc[item.prdtId] = false; acc[item.prdtId] = false;
@@ -321,6 +315,7 @@ export default function RecentlyViewed({ title, panelInfo, isOnTop }) {
return ( return (
<> <>
<THeader <THeader
spotlightId="recentlyviewed_header"
title={title} title={title}
className={css.recentlyViewedHeader} className={css.recentlyViewedHeader}
ariaLabel="RECENTLY VIEWED, heading 1" ariaLabel="RECENTLY VIEWED, heading 1"