File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ export const NoneArrowAccordion: Story = {
6363 ) ;
6464 } ,
6565} ;
66+
6667export const InputAccordion : Story = {
6768 render : ( ) => {
6869 return (
@@ -74,3 +75,18 @@ export const InputAccordion: Story = {
7475 ) ;
7576 } ,
7677} ;
78+
79+ export const DefaultValueAccordion : Story = {
80+ render : ( ) => {
81+ return (
82+ < Accordion type = "single" defaultValue = { [ 'item-2' ] } >
83+ < AccordionItem value = "item-1" isArrow = { false } trigger = "defualtValue를 설정하지 않은 요소" >
84+ 초기 render시 조회되지 않아요
85+ </ AccordionItem >
86+ < AccordionItem value = "item-2" isArrow = { false } trigger = "defualtValue를 설정한 요소" >
87+ 초기 render시 조회돼요
88+ </ AccordionItem >
89+ </ Accordion >
90+ ) ;
91+ } ,
92+ } ;
Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ type AccordionRootProps = {
1717 * The content of the Accordion, typically AccordionItem components.
1818 */
1919 children : ReactNode ;
20+ /**
21+ * The default value of the Accordion item that should be open on initial render.
22+ */
23+ defaultValue ?: string [ ] ;
24+
2025 /**
2126 * Additional class names to apply to the AccordionRoot.
2227 */
@@ -27,9 +32,11 @@ export function AccordionRoot({
2732 type = 'single' ,
2833 className = '' ,
2934 children,
35+ defaultValue,
3036 ...props
3137} : AccordionRootProps ) {
32- const [ openItems , setOpenItems ] = useState < string [ ] > ( [ ] ) ;
38+ const defaultOpenItem = defaultValue ? defaultValue : [ ] ;
39+ const [ openItems , setOpenItems ] = useState < string [ ] > ( defaultOpenItem ) ;
3340
3441 const toggleItem = ( value : string ) => {
3542 if ( type === 'single' ) {
You can’t perform that action at this time.
0 commit comments