@@ -106,32 +106,37 @@ export type TabItemRendererProps = {
106106 menuIcon ?: string ;
107107 eventKey ?: TabKey ;
108108 activeKey ?: TabKey ;
109+ activeTabRef ?: Ref < HTMLAnchorElement > ;
110+ children ?: ReactNode ;
109111 onTabClick ?: ( eventKey : TabKey ) => void ;
110112 onTabKeyDown ?: (
111113 eventKey : TabKey ,
112114 e : React . KeyboardEvent < HTMLAnchorElement >
113115 ) => void ;
114116} ;
115117
116- const DefaultTabItemRenderer : FC < TabItemRendererProps > = ( props ) => {
118+ const DefaultTabItemRenderer : FC = ( props ) => {
117119 const el = React . Children . only ( props . children ) ;
118120 return React . isValidElement ( el ) ? el : < > { el } </ > ;
119121} ;
120122
121123/**
122124 *
123125 */
124- export type TabItemProps = {
125- tabItemRenderer ?: ComponentType < TabItemRendererProps > ;
126+ export type TabItemProps < RendererProps extends TabItemRendererProps > = {
127+ tabItemRenderer ?: ComponentType < RendererProps > ;
128+ rendererProps ?: Omit < RendererProps , keyof TabItemRendererProps > ;
126129} & Omit <
127130 TabItemRendererProps ,
128- 'type' | 'activeKey' | 'onTabClick' | 'onTabKeyDown'
131+ 'type' | 'activeKey' | 'activeTabRef' | ' onTabClick' | 'onTabKeyDown'
129132> ;
130133
131134/**
132135 *
133136 */
134- const TabItem : FC < TabItemProps > = ( props ) => {
137+ const TabItem = < RendererProps extends TabItemRendererProps > (
138+ props : TabItemProps < RendererProps >
139+ ) => {
135140 const { title, eventKey, menu, menuIcon } = props ;
136141 const { type, activeTabRef } = useContext ( TabsContext ) ;
137142 const activeKey = useContext ( TabsActiveKeyContext ) ;
@@ -153,14 +158,21 @@ const TabItem: FC<TabItemProps> = (props) => {
153158 const tabLinkClassName = `slds-tabs_${ type } __link` ;
154159 const {
155160 tabItemRenderer : TabItemRenderer = DefaultTabItemRenderer ,
161+ rendererProps,
156162 ...rprops
157163 } = props ;
164+ const itemRendererProps = {
165+ ...rendererProps ,
166+ ...rprops ,
167+ type,
168+ activeKey,
169+ activeTabRef,
170+ onTabClick,
171+ onTabKeyDown,
172+ } as RendererProps ;
158173 return (
159174 < li className = { tabItemClassName } role = 'presentation' >
160- < TabItemRenderer
161- { ...rprops }
162- { ...{ type, activeKey, onTabClick, onTabKeyDown } }
163- >
175+ < TabItemRenderer { ...itemRendererProps } >
164176 < span className = 'react-slds-tab-item-content' >
165177 < a
166178 className = { tabLinkClassName }
@@ -210,12 +222,17 @@ const TabNav: FC = (props) => {
210222/**
211223 *
212224 */
213- export type TabProps = {
225+ export type TabProps < RendererProps > = {
214226 className ?: string ;
215227 eventKey ?: TabKey ;
216- } & TabItemProps ;
228+ children ?: ReactNode ;
229+ } & TabItemProps < RendererProps > ;
217230
218- export const Tab : FC < TabProps > = ( props ) => {
231+ export const Tab = <
232+ RendererProps extends TabItemRendererProps = TabItemRendererProps
233+ > (
234+ props : TabProps < RendererProps >
235+ ) => {
219236 const { className, eventKey, children } = props ;
220237 const activeKey = useContext ( TabsActiveKeyContext ) ;
221238 return (
0 commit comments