Skip to content

Commit f6d2025

Browse files
committed
Forward ref to TabList
1 parent f3004e6 commit f6d2025

File tree

1 file changed

+24
-27
lines changed
  • packages/circuit-ui/components/Tabs/components/TabList

1 file changed

+24
-27
lines changed

packages/circuit-ui/components/Tabs/components/TabList/TabList.tsx

+24-27
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { Children, type HTMLAttributes } from 'react';
16+
import { Children, forwardRef, type HTMLAttributes } from 'react';
1717

1818
import { clsx } from '../../../../styles/clsx.js';
1919
import { utilClasses } from '../../../../styles/utility.js';
@@ -29,32 +29,29 @@ const MOBILE_AUTOSTRETCH_ITEMS_MAX = 3;
2929
/**
3030
* TabList component that wraps the Tab components
3131
*/
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 (
4738
<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 }}
5542
>
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>
5754
</div>
58-
</div>
59-
);
60-
}
55+
);
56+
},
57+
);

0 commit comments

Comments
 (0)