13
13
* limitations under the License.
14
14
*/
15
15
16
- import { Children , type HTMLAttributes } from 'react' ;
16
+ import { Children , forwardRef , type HTMLAttributes } from 'react' ;
17
17
18
18
import { clsx } from '../../../../styles/clsx.js' ;
19
19
import { utilClasses } from '../../../../styles/utility.js' ;
@@ -29,32 +29,29 @@ const MOBILE_AUTOSTRETCH_ITEMS_MAX = 3;
29
29
/**
30
30
* TabList component that wraps the Tab components
31
31
*/
32
- export function TabList ( {
33
- className,
34
- style = { } ,
35
- stretched,
36
- children,
37
- ...props
38
- } : TabListProps ) {
39
- const numberOfTabs = Children . toArray ( children ) . length ;
40
- const tabWidth = Math . floor ( 100 / numberOfTabs ) ;
41
- const stretchOnMobile = numberOfTabs <= MOBILE_AUTOSTRETCH_ITEMS_MAX ;
42
- return (
43
- < div
44
- className = { clsx ( classes . wrapper , utilClasses . hideScrollbar , className ) }
45
- style = { { ...style , '--tab-list-width' : tabWidth } }
46
- >
32
+ export const TabList = forwardRef < HTMLDivElement , TabListProps > (
33
+ ( { className, style = { } , stretched, children, ...props } , ref ) => {
34
+ const numberOfTabs = Children . toArray ( children ) . length ;
35
+ const tabWidth = Math . floor ( 100 / numberOfTabs ) ;
36
+ const stretchOnMobile = numberOfTabs <= MOBILE_AUTOSTRETCH_ITEMS_MAX ;
37
+ return (
47
38
< div
48
- className = { clsx (
49
- classes . base ,
50
- stretched && classes . stretched ,
51
- stretchOnMobile && classes [ 'stretched-mobile' ] ,
52
- ) }
53
- { ...props }
54
- role = "tablist"
39
+ ref = { ref }
40
+ className = { clsx ( classes . wrapper , utilClasses . hideScrollbar , className ) }
41
+ style = { { ...style , '--tab-list-width' : tabWidth } }
55
42
>
56
- { children }
43
+ < div
44
+ className = { clsx (
45
+ classes . base ,
46
+ stretched && classes . stretched ,
47
+ stretchOnMobile && classes [ 'stretched-mobile' ] ,
48
+ ) }
49
+ { ...props }
50
+ role = "tablist"
51
+ >
52
+ { children }
53
+ </ div >
57
54
</ div >
58
- </ div >
59
- ) ;
60
- }
55
+ ) ;
56
+ } ,
57
+ ) ;
0 commit comments