@@ -72,27 +72,61 @@ function TabList({
7272 } ,
7373 className
7474 ) } >
75- { tabValues . map ( ( { value, label, attributes } ) => (
76- < li
77- // TODO extract TabListItem
78- role = "tab"
79- tabIndex = { selectedValue === value ? 0 : - 1 }
80- aria-selected = { selectedValue === value }
81- key = { value }
82- ref = { tabControl => tabRefs . push ( tabControl ) }
83- onKeyDown = { handleKeydown }
84- onClick = { handleTabChange }
85- { ...attributes }
86- className = { clsx ( 'tabs__item' , styles . tabItem , attributes ?. className as string , {
87- 'tabs__item--active' : selectedValue === value ,
88- } ) } >
89- { label ?? value }
90- </ li >
75+ { tabValues . map ( ( tabValue ) => (
76+ < TabListItem
77+ key = { tabValue . value }
78+ value = { tabValue . value }
79+ label = { tabValue . label }
80+ attributes = { tabValue . attributes }
81+ selectedValue = { selectedValue }
82+ handleTabChange = { handleTabChange }
83+ handleKeydown = { handleKeydown }
84+ setRef = { ( tabControl ) => tabRefs . push ( tabControl ) }
85+ />
9186 ) ) }
9287 </ ul >
9388 )
9489}
9590
91+ function TabListItem ( {
92+ value,
93+ label,
94+ attributes,
95+ selectedValue,
96+ handleTabChange,
97+ handleKeydown,
98+ setRef,
99+ } : {
100+ value : string
101+ label ?: string
102+ attributes ?: { [ key : string ] : unknown ; className ?: string }
103+ selectedValue : string
104+ handleTabChange : (
105+ event :
106+ | React . FocusEvent < HTMLLIElement >
107+ | React . MouseEvent < HTMLLIElement >
108+ | React . KeyboardEvent < HTMLLIElement >
109+ ) => void
110+ handleKeydown : ( event : React . KeyboardEvent < HTMLLIElement > ) => void
111+ setRef : ( element : HTMLLIElement | null ) => void
112+ } ) {
113+ return (
114+ < li
115+ role = "tab"
116+ tabIndex = { selectedValue === value ? 0 : - 1 }
117+ aria-selected = { selectedValue === value }
118+ ref = { setRef }
119+ onKeyDown = { handleKeydown }
120+ onClick = { handleTabChange }
121+ { ...attributes }
122+ className = { clsx ( 'tabs__item' , styles . tabItem , attributes ?. className as string , {
123+ 'tabs__item--active' : selectedValue === value ,
124+ } ) } >
125+ { label ?? value }
126+ </ li >
127+ )
128+ }
129+
96130function TabContent ( { lazy, children, selectedValue } : Props & ReturnType < typeof useTabs > ) {
97131 const childTabs = ( Array . isArray ( children ) ? children : [ children ] ) . filter (
98132 Boolean
0 commit comments