@@ -13,7 +13,7 @@ import {
13
13
} from '@builder.io/qwik' ;
14
14
import { KeyCode } from '../../utils/key-code.type' ;
15
15
import { Behavior } from './behavior.type' ;
16
- import { TAB_ID_PREFIX , Tab , TabProps } from './tab' ;
16
+ import { Tab , TabProps } from './tab' ;
17
17
import { TabPanel , TabPanelProps } from './tab-panel' ;
18
18
import { tabsContextId } from './tabs-context-id' ;
19
19
import { TabsContext } from './tabs-context.type' ;
@@ -40,8 +40,7 @@ import { TabList } from './tabs-list';
40
40
- do we keep all current props (tabId callbacks?)
41
41
- shorthand for tab: "label" or "tab"?
42
42
- the TODOs
43
- - why id and data-tab-id? we don't need any of them
44
- *
43
+ *
45
44
*/
46
45
47
46
export type TabsProps = {
@@ -120,7 +119,7 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
120
119
let tabListElement : JSXNode | undefined ;
121
120
const tabComponents : JSXNode [ ] = [ ] ;
122
121
const panelComponents : JSXNode [ ] = [ ] ;
123
- const tabs : TabInfo [ ] = [ ] ;
122
+ const tabsInfo : TabInfo [ ] = [ ] ;
124
123
let panelIndex = 0 ;
125
124
let selectedIndex ;
126
125
@@ -156,7 +155,8 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
156
155
case TabPanel : {
157
156
const { label, selected } = child . props ;
158
157
// The consumer must provide a key if they change the order
159
- const tabId = tabComponents [ panelIndex ] ?. key || child . key || `${ panelIndex } ` ;
158
+ const tabIdFromTabMaybe = tabComponents [ panelIndex ] ?. key ;
159
+ const tabId = tabIdFromTabMaybe || child . key || `${ panelIndex } ` ;
160
160
161
161
if ( label ) {
162
162
tabComponents . push ( < Tab > { label } </ Tab > ) ;
@@ -173,7 +173,7 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
173
173
child . props . _extraClass = panelClass ;
174
174
175
175
panelComponents . push ( child ) ;
176
- tabs . push ( {
176
+ tabsInfo . push ( {
177
177
tabId,
178
178
index : panelIndex ,
179
179
panelProps : child . props
@@ -195,11 +195,11 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
195
195
}
196
196
197
197
tabComponents . forEach ( ( tab , index ) => {
198
- const tabId = tabs [ index ] ?. tabId ;
198
+ const tabId = tabsInfo [ index ] ?. tabId ;
199
199
tab . key = tabId ;
200
200
tab . props . _tabId = tabId ;
201
201
tab . props . _extraClass = tabClass ;
202
- tabs [ index ] . tabProps = tab . props ;
202
+ tabsInfo [ index ] . tabProps = tab . props ;
203
203
} ) ;
204
204
205
205
if ( tabListElement ) {
@@ -215,7 +215,7 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
215
215
}
216
216
217
217
return (
218
- < TabsImpl tabs = { tabs } { ...rest } >
218
+ < TabsImpl tabs = { tabsInfo } { ...rest } >
219
219
{ tabListElement }
220
220
{ panelComponents }
221
221
</ TabsImpl >
@@ -276,6 +276,8 @@ export const TabsImpl = component$((props: TabsProps & { tabs: TabInfo[] }) => {
276
276
const selectedTabIdSig = givenTabIdSig || initialSelectedTabIdSig ;
277
277
278
278
useTask$ ( function syncTabsTask ( { track } ) {
279
+ // Possible optimizer bug: tracking only works with props.tabs
280
+ // TODO: Write a test in Qwik optimizer to prove this bug
279
281
const tabs = track ( ( ) => props . tabs ) ;
280
282
const tabId = selectedTabIdSig . value ;
281
283
updateSignals ( tabs , selectedIndexSig , selectedTabIdSig , { tabId } , true ) ;
@@ -350,15 +352,11 @@ export const TabsImpl = component$((props: TabsProps & { tabs: TabInfo[] }) => {
350
352
tab = findPrevEnabledTab ( props . tabs , props . tabs . length ) ;
351
353
}
352
354
if ( tab ) {
353
- focusOnTab ( tab . tabId ) ;
355
+ focusOnTab ( tab . index ) ;
354
356
}
355
357
356
- function focusOnTab ( tabId : string ) {
357
- const fullTabElementId = tabsPrefix + TAB_ID_PREFIX + tabId ;
358
- // TODO use the index
359
- tabsRootElement
360
- ?. querySelector < HTMLElement > ( `[data-tab-id='${ fullTabElementId } ']` )
361
- ?. focus ( ) ;
358
+ function focusOnTab ( index : number ) {
359
+ tabsRootElement ?. children [ 0 ] ?. children [ index ] ?. focus ( ) ;
362
360
}
363
361
} ) ;
364
362
0 commit comments