@@ -82,48 +82,51 @@ export const TabList = component$((props: TabListProps) => {
8282interface TabProps {
8383 onClick ?: PropFunction < ( clicked : number ) => void > ;
8484 class ?: string ;
85+ selectedClassName ?: string ;
8586}
8687
8788// Tab button inside of a tab list
88- export const Tab = component$ ( ( { onClick, ...props } : TabProps ) => {
89- const contextService = useContext ( tabsContext ) ;
90- const thisTabIndex = useSignal ( 0 ) ;
91-
92- useMount$ ( async ( ) => {
93- thisTabIndex . value = await await contextService . getNextTabIndex ( ) ;
94- } ) ;
95- const isSelected = ( ) =>
96- thisTabIndex . value === contextService . selectedIndex . value ;
89+ export const Tab = component$ (
90+ ( { selectedClassName, onClick, ...props } : TabProps ) => {
91+ const contextService = useContext ( tabsContext ) ;
92+ const thisTabIndex = useSignal ( 0 ) ;
9793
98- const selectIfAutomatic = $ ( ( ) => {
99- if ( contextService . behavior === 'automatic' ) {
100- contextService . selectedIndex . value = thisTabIndex . value ;
101- }
102- } ) ;
94+ useMount$ ( async ( ) => {
95+ thisTabIndex . value = await await contextService . getNextTabIndex ( ) ;
96+ } ) ;
97+ const isSelected = ( ) =>
98+ thisTabIndex . value === contextService . selectedIndex . value ;
10399
104- return (
105- < button
106- id = { `${ contextService . tabsHash } -tab-${ thisTabIndex . value } ` }
107- type = "button"
108- role = "tab"
109- onFocus$ = { selectIfAutomatic }
110- onMouseEnter$ = { selectIfAutomatic }
111- aria-selected = { isSelected ( ) }
112- aria-controls = { `tabpanel-${ thisTabIndex . value } ` }
113- class = { `${ isSelected ( ) ? 'selected' : '' } ${
114- props . class ? ` ${ props . class } ` : ''
115- } `}
116- onClick$ = { $ ( ( ) => {
100+ const selectIfAutomatic = $ ( ( ) => {
101+ if ( contextService . behavior === 'automatic' ) {
117102 contextService . selectedIndex . value = thisTabIndex . value ;
118- if ( onClick ) {
119- onClick ( thisTabIndex . value ) ;
120- }
121- } ) }
122- >
123- < Slot />
124- </ button >
125- ) ;
126- } ) ;
103+ }
104+ } ) ;
105+
106+ return (
107+ < button
108+ id = { `${ contextService . tabsHash } -tab-${ thisTabIndex . value } ` }
109+ type = "button"
110+ role = "tab"
111+ onFocus$ = { selectIfAutomatic }
112+ onMouseEnter$ = { selectIfAutomatic }
113+ aria-selected = { isSelected ( ) }
114+ aria-controls = { `tabpanel-${ thisTabIndex . value } ` }
115+ class = { `${ isSelected ( ) ? `selected ${ selectedClassName } ` : '' } ${
116+ props . class ? ` ${ props . class } ` : ''
117+ } `}
118+ onClick$ = { $ ( ( ) => {
119+ contextService . selectedIndex . value = thisTabIndex . value ;
120+ if ( onClick ) {
121+ onClick ( thisTabIndex . value ) ;
122+ }
123+ } ) }
124+ >
125+ < Slot />
126+ </ button >
127+ ) ;
128+ }
129+ ) ;
127130
128131interface TabPanelProps {
129132 class ?: string ;
0 commit comments