Skip to content

[REFACTOR] Accordion 컴포넌트의 defaultValue prop 지원#85

Merged
yougyung merged 2 commits intomainfrom
refactor/#83
Oct 17, 2025
Merged

[REFACTOR] Accordion 컴포넌트의 defaultValue prop 지원#85
yougyung merged 2 commits intomainfrom
refactor/#83

Conversation

@yougyung
Copy link
Copy Markdown
Collaborator

@yougyung yougyung commented Oct 16, 2025

🔥 연관 이슈

🚀 작업 내용

  • 마이그레이션 작업과정에서 Accordion 컴포넌트의 defaultValue 지원이 필요해, 기능을 추가했어요.
    • AccordiondefaultValue 속성에 AccordionItemvalue를 설정해주면 초기 화면 렌더시 open되어져있는 상태를 구현 가능합니다.
스크린샷 2025-10-16 오후 5 10 06

Summary by CodeRabbit

릴리스 노트

  • 새로운 기능

    • 아코디언 컴포넌트에서 초기 렌더링 시 기본으로 열릴 항목들을 지정할 수 있는 기능이 추가되었습니다 (페이지 로드 시 특정 항목 자동 오픈).
  • 문서

    • 아코디언 사용 예시를 보여주는 새로운 스토리(기본값이 설정된 변형)가 추가되었습니다.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 16, 2025

Walkthrough

Accordion 루트 컴포넌트에 defaultValue?: string[] prop을 추가하여 초기 열린 항목을 해당 값으로 설정하도록 상태 초기화를 변경하고, 이 동작을 검증하는 DefaultValueAccordion 스토리를 추가했습니다.

Changes

Cohort / File(s) 변경 요약
Accordion 핵심 로직 업데이트
src/shared/ui/Accordion/Accordion.tsx
AccordionRootPropsdefaultValue?: string[] 추가. AccordionRoot 시그니처에 defaultValue 인자 추가 및 openItems 초기값을 defaultValue에서 파생되도록 변경. 기존 토글/렌더 흐름에는 변경 없음.
스토리 예제 추가
src/shared/ui/Accordion/Accordion.stories.tsx
새로운 DefaultValueAccordion 스토리 추가: defaultValue={['item-2']}로 초기 열린 항목을 지정한 Accordion 예제 추가.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev
  participant Story as Storybook Story
  participant Accordion as AccordionRoot
  participant State as openItems State

  Note over Story,Accordion: 스토리에서 Accordion을 defaultValue로 렌더링
  Story->>Accordion: render(defaultValue=['item-2'])
  Accordion->>State: initialize openItems from defaultValue
  State-->>Accordion: openItems = ['item-2']
  Accordion->>Accordion: render items with initial open state
  Note right of Accordion: 기존 토글 로직은 변경 없음
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8분

Suggested reviewers

  • ujinsim
  • keemsebin

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed PR 제목 "[REFACTOR] Accordion 컴포넌트의 defaultValue prop 지원"은 변경 사항의 핵심을 명확하게 나타냅니다. 제목은 어떤 컴포넌트가 수정되었는지(Accordion), 어떤 작업이 이루어졌는지([REFACTOR]), 그리고 추가된 기능이 무엇인지(defaultValue prop 지원)를 구체적으로 설명하고 있어 PR의 주요 목적을 한 번에 파악할 수 있습니다.
Linked Issues Check ✅ Passed 연관된 이슈 #83의 목표는 "Accordion 컴포넌트에 defaultValue Prop을 추가하여 초기 렌더링 시 열려 있는 아이템을 지정할 수 있도록 지원"하는 것입니다. 실제 변경사항을 보면 AccordionRootProps에 defaultValue?: string[] 속성을 추가했고, AccordionRoot 컴포넌트에서 이를 활용하여 openItems 상태를 초기화하고 있으며, 이 기능을 시연하는 DefaultValueAccordion 스토리도 추가했습니다. 모든 구현이 이슈의 요구사항과 일치합니다.
Out of Scope Changes Check ✅ Passed PR의 모든 변경사항은 연관된 이슈 #83의 범위 내에 있습니다. Accordion.tsx에서 defaultValue 속성과 관련 로직을 추가한 점, 그리고 Accordion.stories.tsx에서 이 기능을 테스트하는 스토리를 추가한 점 모두 defaultValue prop 지원 구현이라는 목표와 직결되어 있습니다. 범위 밖의 변경사항은 발견되지 않습니다.
Description Check ✅ Passed PR 설명은 필수 항목들이 채워져 있습니다. "🔥 연관 이슈" 섹션에서 #83을 명시하고 있으며, "🚀 작업 내용" 섹션에서 defaultValue 기능의 목적과 사용 방법을 명확히 설명하고 있고, 기능 동작을 시각적으로 보여주는 스크린샷도 포함되어 있습니다. "🤔 고민했던 내용"과 "💬 리뷰 중점사항" 섹션이 비어있지만, 주요 정보는 충분히 전달되고 있습니다.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/#83

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 16, 2025

Update: 2025년 10월 16일 17시 21분 26초
Storybook 미리보기: https://677a9a76c58a295e9421d3ef-gyecjfhxvk.chromatic.com/

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/shared/ui/Accordion/Accordion.tsx (1)

31-49: 단일 모드에서 여러 기본값에 대한 유효성 검사를 고려하세요.

type="single"일 때 defaultValue에 여러 항목이 포함되면, 초기 렌더링에서 여러 항목이 열린 상태로 표시되어 단일 선택 제약을 위반합니다. 사용자가 상호작용하면 단일 항목으로 축소되지만, 초기 상태의 불일치가 혼란을 줄 수 있습니다.

초기화 시 유효성 검사를 추가하는 것을 고려하세요:

-  const defaultOpenItem = defaultValue ? defaultValue : [];
+  const defaultOpenItem = defaultValue ?? [];
+  
+  // Validate: for single mode, only use the first item
+  const initialOpenItems = type === 'single' && defaultOpenItem.length > 1 
+    ? [defaultOpenItem[0]] 
+    : defaultOpenItem;
+  
-  const [openItems, setOpenItems] = useState<string[]>(defaultOpenItem);
+  const [openItems, setOpenItems] = useState<string[]>(initialOpenItems);

또는 개발 모드에서 경고를 표시할 수 있습니다:

if (process.env.NODE_ENV === 'development' && type === 'single' && defaultOpenItem.length > 1) {
  console.warn('Accordion: defaultValue should contain only one item when type is "single"');
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9345ad8 and 2bfda60.

📒 Files selected for processing (2)
  • src/shared/ui/Accordion/Accordion.stories.tsx (2 hunks)
  • src/shared/ui/Accordion/Accordion.tsx (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/shared/ui/Accordion/Accordion.stories.tsx (2)
src/shared/ui/Accordion/Accordion.tsx (1)
  • AccordionItem (103-172)
src/shared/ui/Accordion/index.ts (1)
  • AccordionItem (2-2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: preview-storybook

Comment on lines +79 to +92
export const DefaultValueAccordion: Story = {
render: () => {
return (
<Accordion type="multiple" defaultValue={['item-2']}>
<AccordionItem value="item-1" isArrow={false} trigger={<div>질문 1</div>}>
<div>내용</div>
</AccordionItem>
<AccordionItem value="item-2" isArrow={false} trigger={<div>질문 1</div>}>
<div>내용</div>
</AccordionItem>
</Accordion>
);
},
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

스토리 코드는 잘 작동하지만, trigger 텍스트에 오타가 있습니다.

86번 라인에서 두 번째 AccordionItem의 trigger가 "질문 1"로 되어 있는데, "질문 2"로 수정해야 합니다. 첫 번째 아이템과 동일한 텍스트가 표시되어 혼란을 줄 수 있습니다.

다음 diff를 적용하여 수정하세요:

-        <AccordionItem value="item-2" isArrow={false} trigger={<div>질문 1</div>}>
+        <AccordionItem value="item-2" isArrow={false} trigger={<div>질문 2</div>}>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const DefaultValueAccordion: Story = {
render: () => {
return (
<Accordion type="multiple" defaultValue={['item-2']}>
<AccordionItem value="item-1" isArrow={false} trigger={<div>질문 1</div>}>
<div>내용</div>
</AccordionItem>
<AccordionItem value="item-2" isArrow={false} trigger={<div>질문 1</div>}>
<div>내용</div>
</AccordionItem>
</Accordion>
);
},
};
export const DefaultValueAccordion: Story = {
render: () => {
return (
<Accordion type="multiple" defaultValue={['item-2']}>
<AccordionItem value="item-1" isArrow={false} trigger={<div>질문 1</div>}>
<div>내용</div>
</AccordionItem>
<AccordionItem value="item-2" isArrow={false} trigger={<div>질문 2</div>}>
<div>내용</div>
</AccordionItem>
</Accordion>
);
},
};
🤖 Prompt for AI Agents
In src/shared/ui/Accordion/Accordion.stories.tsx around lines 79 to 92, the
second AccordionItem's trigger text is incorrect — it currently reads "질문 1" on
line ~86 but should be "질문 2"; update that trigger prop to "질문 2" so each item
displays the correct, distinct label in the story.

Comment on lines +20 to +23
/**
* The default value of the Accordion item that should be open on initial render.
*/
defaultValue?: string[];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

단일 모드에서 타입 안정성을 개선할 수 있습니다.

defaultValuestring[] 타입으로 정의되어 있지만, type="single"일 때는 의미상 단일 값만 허용되어야 합니다. 현재 구현은 작동하지만, 타입 시스템을 통해 이를 강제하면 더 명확한 API를 제공할 수 있습니다.

타입을 조건부로 정의하는 것을 고려해보세요:

type AccordionRootProps = {
  type?: 'single' | 'multiple';
  children: ReactNode;
  className?: string;
} & (
  | { type?: 'single'; defaultValue?: string }
  | { type?: 'multiple'; defaultValue?: string[] }
);

또는 더 간단하게 유니온 타입을 사용할 수 있습니다:

type AccordionRootProps = {
  type?: 'single' | 'multiple';
  children: ReactNode;
  defaultValue?: string | string[];
  className?: string;
};
🤖 Prompt for AI Agents
In src/shared/ui/Accordion/Accordion.tsx around lines 20 to 23, the prop
defaultValue is currently typed as string[] but should be conditionally typed to
reflect the component's type prop; update the AccordionRootProps so that when
type is "single" defaultValue is a string and when type is "multiple"
defaultValue is a string[] (either by using a discriminated union with two
variants or by using defaultValue?: string | string[] for a simpler change), and
ensure any usages and forwarded props/interfaces are updated to match the new
prop type so TypeScript enforces the correct shape in single vs multiple modes.

...props
}: AccordionRootProps) {
const [openItems, setOpenItems] = useState<string[]>([]);
const defaultOpenItem = defaultValue ? defaultValue : [];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

nullish coalescing 연산자로 간소화할 수 있습니다.

현재 삼항 연산자 대신 nullish coalescing 연산자(??)를 사용하면 코드가 더 간결하고 의도가 명확해집니다.

다음 diff를 적용하세요:

-  const defaultOpenItem = defaultValue ? defaultValue : [];
+  const defaultOpenItem = defaultValue ?? [];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const defaultOpenItem = defaultValue ? defaultValue : [];
const defaultOpenItem = defaultValue ?? [];
🤖 Prompt for AI Agents
In src/shared/ui/Accordion/Accordion.tsx around line 38, replace the ternary
fallback "const defaultOpenItem = defaultValue ? defaultValue : [];" with a
nullish coalescing fallback so the variable uses defaultValue unless it is null
or undefined, otherwise an empty array; update the line to use the ?? operator
and keep the original variable name and intended type.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bfda60 and 7257992.

📒 Files selected for processing (1)
  • src/shared/ui/Accordion/Accordion.stories.tsx (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/shared/ui/Accordion/Accordion.stories.tsx (2)
src/shared/ui/Accordion/Accordion.tsx (1)
  • AccordionItem (103-172)
src/shared/ui/Accordion/index.ts (1)
  • AccordionItem (2-2)
🔇 Additional comments (1)
src/shared/ui/Accordion/Accordion.stories.tsx (1)

79-92: 잘 구현된 스토리입니다.

DefaultValueAccordion 스토리가 새로운 defaultValue prop의 동작을 명확하게 보여주고 있습니다. defaultValue={['item-2']}로 설정하여 두 번째 아이템이 초기 렌더링 시 열린 상태로 표시되는 것을 잘 시연하고 있습니다.

render: () => {
return (
<Accordion type="single" defaultValue={['item-2']}>
<AccordionItem value="item-1" isArrow={false} trigger="defualtValue를 설정하지 않은 요소">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

trigger 텍스트의 오타를 수정하세요.

83번과 86번 라인의 trigger 텍스트에서 "defualtValue"를 "defaultValue"로 수정해야 합니다. 철자 오류가 사용자에게 노출되는 스토리북 문서에 표시됩니다.

다음 diff를 적용하여 수정하세요:

-        <AccordionItem value="item-1" isArrow={false} trigger="defualtValue를 설정하지 않은 요소">
+        <AccordionItem value="item-1" isArrow={false} trigger="defaultValue를 설정하지 않은 요소">
           초기 render시 조회되지 않아요
         </AccordionItem>
-        <AccordionItem value="item-2" isArrow={false} trigger="defualtValue를 설정한 요소">
+        <AccordionItem value="item-2" isArrow={false} trigger="defaultValue를 설정한 요소">
           초기 render시 조회돼요
         </AccordionItem>

Also applies to: 86-86

🤖 Prompt for AI Agents
In src/shared/ui/Accordion/Accordion.stories.tsx around lines 83 and 86, there
is a spelling mistake in the trigger text ("defualtValue") exposed in Storybook;
update both occurrences on lines 83 and 86 to "defaultValue" so the displayed
trigger text reads correctly.

Copy link
Copy Markdown
Contributor

@keemsebin keemsebin left a comment

Choose a reason for hiding this comment

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

수고하셨습니다~!

@yougyung yougyung merged commit ef24e47 into main Oct 17, 2025
7 checks passed
@yougyung yougyung deleted the refactor/#83 branch October 17, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REFACTOR] Accordion 컴포넌트 defaultValue prop 지원

2 participants