File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed
packages/kit-headless/src/components/tabs Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 99 useVisibleTask$ ,
1010 QwikIntrinsicElements ,
1111 type QwikMouseEvent ,
12+ useComputed$ ,
1213} from '@builder.io/qwik' ;
1314import { tabsContextId } from './tabs-context-id' ;
1415import { KeyCode } from '../../utils/key-code.type' ;
@@ -39,6 +40,10 @@ export const Tab = component$((props: TabProps) => {
3940 const elementRefSig = useSignal < HTMLElement | undefined > ( ) ;
4041 const uniqueTabId = useId ( ) ;
4142
43+ const selectedClassNameSig = useComputed$ ( ( ) => {
44+ return props . selectedClassName || contextService . selectedClassName ;
45+ } ) ;
46+
4247 useTask$ ( async function indexInitTask ( { cleanup } ) {
4348 if ( isServer ) {
4449 serverAssignedIndexSig . value =
@@ -112,14 +117,17 @@ export const Tab = component$((props: TabProps) => {
112117 tabIndex = { isSelectedSig . value ? 0 : - 1 }
113118 aria-controls = { 'tabpanel-' + matchedTabPanelIdSig . value }
114119 class = { `${
115- isSelectedSig . value ? `selected ${ props . selectedClassName || '' } ` : ''
120+ isSelectedSig . value
121+ ? `selected ${ selectedClassNameSig . value || '' } `
122+ : ''
116123 } ${ props . class ? ` ${ props . class } ` : '' } `}
117124 onClick$ = { ( event ) => {
118125 contextService . selectTab$ ( uniqueTabId ) ;
119126 if ( props . onClick$ ) {
120127 props . onClick$ ( event ) ;
121128 }
122129 } }
130+ style = { props . style }
123131 >
124132 < Slot />
125133 </ button >
Original file line number Diff line number Diff line change 11import { QRL } from '@builder.io/qwik' ;
2- import { Behavior } from './behavior.type' ;
32import { TabInfo } from './tabs' ;
43import { KeyCode } from '../../utils/key-code.type' ;
54
@@ -16,4 +15,5 @@ export interface TabsContext {
1615 isTabSelected$ : QRL < ( tabId : string ) => boolean > ;
1716 isPanelSelected$ : QRL < ( panelId : string ) => boolean > ;
1817 selectIfAutomatic$ : QRL < ( tabId : string ) => void > ;
18+ selectedClassName ?: string ;
1919}
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ export type TabsProps = {
4646 behavior ?: Behavior ;
4747 selectedIndex ?: number ;
4848 vertical ?: boolean ;
49+ selectedClassName ?: string ;
4950 onSelectedIndexChange$ ?: ( index : number ) => void ;
5051} & QwikIntrinsicElements [ 'div' ] ;
5152
@@ -214,6 +215,7 @@ export const Tabs = component$((props: TabsProps) => {
214215 reIndexTabs$,
215216 onTabKeyDown$,
216217 selectIfAutomatic$,
218+ selectedClassName : props . selectedClassName
217219 } ;
218220
219221 useContextProvider ( tabsContextId , contextService ) ;
You can’t perform that action at this time.
0 commit comments