Skip to content
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

lightHouse 웹 접근성 93점을 98점으로 올렸음 #701

Merged
merged 6 commits into from
Oct 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ProgressBarProps {
export default function ProgressBar({ percent, isSelected }: ProgressBarProps) {
return (
<S.Container>
<S.Bar progress={percent} $isSelected={isSelected} />
<S.Bar $progress={percent} $isSelected={isSelected} />
</S.Container>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export const Container = styled.div`
background-color: rgba(0, 0, 0, 0.15);
`;

export const Bar = styled.div<{ progress: number; $isSelected: boolean }>`
export const Bar = styled.div<{ $progress: number; $isSelected: boolean }>`
border-radius: 4px;

width: ${({ progress }) => `${progress}%`};
width: ${({ $progress }) => `${$progress}%`};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

height: 8px;

background-color: ${({ $isSelected }) => ($isSelected ? 'var(--primary-color)' : '#9F9F9F')};
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/post/Post/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useContext, useEffect } from 'react';
import { ForwardedRef, forwardRef, memo, useContext, useEffect } from 'react';

import { PostInfo } from '@type/post';

Expand Down Expand Up @@ -29,7 +29,10 @@ interface PostProps {
isPreview: boolean;
}

export default memo(function Post({ postInfo, isPreview }: PostProps) {
const Post = forwardRef(function Post(
{ postInfo, isPreview }: PostProps,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwardRef 가 이런식으로 사용하는거군요!
react는 흥미로운 메서드가 정말 많네요🤔
새롭게 알아갑니다👍😃

(아래는 공식문서로 찾아본 내용)

DOM 노드를 상위 구성 요소에 노출
기본적으로 각 구성 요소의 DOM 노드는 비공개입니다. 그러나 때로는 DOM 노드를 상위 노드에 노출하는 것이 유용할 때도 있습니다. 예를 들어 DOM 노드에 초점을 맞추도록 허용하는 것입니다.

ref: ForwardedRef<HTMLLIElement>
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ForwardRef 라는 타입이 따로 있군요👍

const {
postId,
category,
Expand Down Expand Up @@ -110,7 +113,7 @@ export default memo(function Post({ postInfo, isPreview }: PostProps) {
const isPreviewTabIndex = isPreview ? undefined : 0;

return (
<S.Container as={isPreview ? 'li' : 'div'}>
<S.Container as={isPreview ? 'li' : 'div'} ref={ref} $isPreview={isPreview}>
<S.DetailLink
as={isPreview ? '' : 'main'}
to={isPreview ? `${PATH.POST}/${postId}` : '#'}
Expand Down Expand Up @@ -195,3 +198,5 @@ export default memo(function Post({ postInfo, isPreview }: PostProps) {
</S.Container>
);
});

export default memo(Post);
5 changes: 4 additions & 1 deletion frontend/src/components/post/Post/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { styled } from 'styled-components';

import { theme } from '@styles/theme';

export const Container = styled.li`
export const Container = styled.li<{ $isPreview: boolean }>`
width: 100%;

position: relative;
Expand All @@ -13,6 +13,9 @@ export const Container = styled.li`
letter-spacing: 0.5px;
line-height: 1.5;

padding-bottom: ${({ $isPreview }) => $isPreview && '30px'};
border-bottom: ${({ $isPreview }) => $isPreview && '1px solid rgba(0, 0, 0, 0.1)'};

@media (min-width: ${theme.breakpoint.sm}) {
font: var(--text-caption);
}
Expand Down
21 changes: 8 additions & 13 deletions frontend/src/components/post/PostList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,18 @@ export default function PostList() {
<React.Fragment key={pageIndex}>
{postListInfo.postList.map((post, index) => {
if (index === 7) {
return (
<div key={post.postId} ref={targetRef}>
<Post isPreview={true} postInfo={post} />
</div>
);
return <Post key={post.postId} ref={targetRef} isPreview={true} postInfo={post} />;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드도 훨씬 깔끔하네요

}

return <Post key={post.postId} isPreview={true} postInfo={post} />;
})}
<S.HiddenButton
onClick={focusTopContent}
aria-label="스크롤 맨 위로가기"
></S.HiddenButton>
<S.HiddenLink
aria-label="게시글 작성 페이지로 이동"
to={PATH.POST_WRITE}
></S.HiddenLink>
<li key={`${pageIndex}UserButton`}>
<S.HiddenButton
onClick={focusTopContent}
aria-label="스크롤 맨 위로가기"
></S.HiddenButton>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 부분이지만 아래처럼 self-closing tag로 작성해도 좋을 것 같아요!

<S.HiddenButton
                onClick={focusTopContent}
                aria-label="스크롤 맨 위로가기"
              / >

<S.HiddenLink aria-label="게시글 작성 페이지로 이동" to={PATH.POST_WRITE} />
</li>
</React.Fragment>
))}
{isFetchingNextPage && <Skeleton isLarge={false} />}
Expand Down
15 changes: 5 additions & 10 deletions frontend/src/components/post/PostList/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ export const PostListContainer = styled.ul`
gap: 30px;

padding: 30px 20px;

> div > li {
padding-bottom: 30px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

> li {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용처로 코드를 이동시키니 이해가 훨씬 잘 되네요bb

padding-bottom: 30px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
`;

export const SelectWrapper = styled.div`
Expand All @@ -61,3 +51,8 @@ export const HiddenButton = styled.button`
export const HiddenLink = styled(Link)`
position: absolute;
`;

export const HiddenList = styled.li`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 이거 혹시 어디에 쓰이는 코드인가요??

padding-bottom: none;
border-bottom: none;
`;
Loading