@@ -120,44 +120,46 @@ function TabGroup({
120120 } ,
121121 [ orientation , variant , refContainer , dashRect ]
122122 )
123-
123+ console . log ( refContainer . current ?. children )
124124 const onClick = useCallback (
125- ( e : MouseEvent < HTMLButtonElement > ) => {
126- const nodes = Array . from (
127- refContainer . current ?. children ?? [ ]
128- ) as HTMLElement [ ]
129- const newValue = nodes . indexOf ( e . currentTarget as unknown as HTMLElement ) // 👈 en vez de e.target
125+ ( event : MouseEvent < HTMLButtonElement > ) => {
126+ const nodes = Array . prototype . slice . call ( refContainer . current ?. children )
127+ const newValue = nodes . indexOf ( event . target ) ?? 0
130128 handleChangeIndicator ( newValue )
131- onChange ?.( newValue )
129+ onChange && onChange ( newValue )
130+
131+ const tabElement = nodes [
132+ newValue !== 0 ? newValue + 1 : newValue
133+ ] as HTMLElement
134+
135+ if ( tabElement )
136+ tabElement . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' } )
132137 } ,
133- [ handleChangeIndicator , onChange ]
138+ [ refContainer , handleChangeIndicator , onChange ]
134139 )
135140
136141 const childrenWithProps = useCallback ( ( ) : ReactNode => {
137- const visibles = React . Children . toArray ( children ) . filter (
138- ( children ) : children is React . ReactElement =>
139- React . isValidElement ( children ) && ! children . props ?. hidden
140- )
141-
142- return visibles . map ( ( child , visibleIndex ) =>
143- React . cloneElement ( child , {
144- index : visibleIndex ,
145- 'data-tab-index' : visibleIndex ,
146- value,
147- onClick,
148- textColor,
149- textDisabledColor,
150- variant,
151- disabledText,
152- tabWidth,
153- tabMinWidth,
154- className : childClassName ,
155- isVertical : orientation === 'vertical' ,
156- ...child . props
157- } )
158- )
142+ return React . Children . map ( children , ( child , index ) : ReactNode => {
143+ if ( React . isValidElement ( child ) ) {
144+ return React . cloneElement ( child as React . ReactElement , {
145+ index,
146+ value,
147+ onClick,
148+ textColor,
149+ textDisabledColor,
150+ variant,
151+ disabledText,
152+ tabWidth,
153+ tabMinWidth,
154+ className : childClassName ,
155+ isVertical : orientation === 'vertical' ,
156+ ...child . props
157+ } )
158+ }
159+ if ( ( child as React . ReactElement ) ?. props ?. hidden ) return null
160+ return child
161+ } )
159162 } , [
160- children ,
161163 value ,
162164 onClick ,
163165 disabledText ,
@@ -167,7 +169,7 @@ function TabGroup({
167169 variant ,
168170 tabWidth ,
169171 tabMinWidth ,
170- orientation
172+ children
171173 ] )
172174
173175 useEffect ( ( ) => {
0 commit comments