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

[FE] refactor: 리뷰 폼 웹 접근성 개선 #12

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/Recipe/CommentForm/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const Form = styled.form`
const CommentTextarea = styled(Textarea)`
height: 50px;
padding: 8px;
font-size: 1.4rem;
`;

const SubmitButton = styled(Button)`
Expand Down
43 changes: 11 additions & 32 deletions src/components/Review/ReviewTagList/ReviewTagList.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Button, Heading, Spacing } from '@fun-eat/design-system';
import { Heading, Spacing } from '@fun-eat/design-system';
import styled from 'styled-components';

import ReviewTagItem from '../ReviewTagItem/ReviewTagItem';

import { SvgIcon } from '@/components/Common';
import { MIN_DISPLAYED_TAGS_LENGTH, TAG_TITLE } from '@/constants';
import { TAG_TITLE } from '@/constants';
import { useReviewTagsQuery } from '@/hooks/queries/review';
import { useDisplayTag } from '@/hooks/review';

interface ReviewTagListProps {
selectedTags: number[];
}

const ReviewTagList = ({ selectedTags }: ReviewTagListProps) => {
const { data: tagsData } = useReviewTagsQuery();
const { minDisplayedTags, canShowMore, showMoreTags } = useDisplayTag(tagsData, MIN_DISPLAYED_TAGS_LENGTH);

return (
<ReviewTagListContainer>
Expand All @@ -31,7 +28,7 @@ const ReviewTagList = ({ selectedTags }: ReviewTagListProps) => {
</TagTitle>
<Spacing size={20} />
<ul>
{tags.slice(0, minDisplayedTags).map(({ id, name }) => (
{tags.map(({ id, name }) => (
<>
<li key={id}>
<ReviewTagItem id={id} name={name} variant={tagType} isSelected={selectedTags.includes(id)} />
Expand All @@ -44,19 +41,6 @@ const ReviewTagList = ({ selectedTags }: ReviewTagListProps) => {
))}
</TagListWrapper>
<Spacing size={26} />
{canShowMore && (
<Button
type="button"
customHeight="fit-content"
variant="transparent"
onClick={showMoreTags}
aria-label="태그 더보기"
>
<SvgWrapper>
<SvgIcon variant="arrow" width={15} />
</SvgWrapper>
</Button>
)}
</ReviewTagListContainer>
);
};
Expand All @@ -80,21 +64,21 @@ const TagListWrapper = styled.div`
column-gap: 20px;
overflow-x: auto;

&::-webkit-scrollbar {
display: none;
}

& > div {
flex-grow: 1;
}

@media screen and (min-width: 420px) {
justify-content: center;

& > div {
flex-grow: 0;
}
}

&::-webkit-scrollbar {
display: none;
}

& > div {
flex-grow: 1;
}
`;

const TagItemWrapper = styled.div`
Expand All @@ -107,8 +91,3 @@ const TagItemWrapper = styled.div`
const TagTitle = styled(Heading)`
text-align: center;
`;

const SvgWrapper = styled.span`
display: inline-block;
transform: rotate(270deg);
`;
3 changes: 3 additions & 0 deletions src/contexts/ReviewFormContext.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { PropsWithChildren } from 'react';
import { createContext, useState } from 'react';

Expand Down Expand Up @@ -27,13 +28,15 @@ export const ReviewFormActionContext = createContext<ReviewFormAction | null>(nu

const ReviewFormProvider = ({ children }: PropsWithChildren) => {
const [reviewFormValue, setReviewFormValue] = useState(initialReviewFormValue);
const { toast } = useToastActionContext();

const handleReviewFormValue = ({ target, value, isSelected }: ReviewFormActionParams) => {
setReviewFormValue((prev) => {
const targetValue = prev[target];

if (Array.isArray(targetValue)) {
if (targetValue.length >= MIN_DISPLAYED_TAGS_LENGTH && !isSelected) {
toast.success(`태그는 ${MIN_DISPLAYED_TAGS_LENGTH}개까지 선택할 수 있습니다`);
return prev;
}

Expand Down
1 change: 0 additions & 1 deletion src/hooks/review/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default as useDisplayTag } from './useDisplayTag';
export { default as useStarRatingHover } from './useStarRatingHover';
21 changes: 0 additions & 21 deletions src/hooks/review/useDisplayTag.ts

This file was deleted.

Loading