@@ -13,7 +13,7 @@ import {
1313} from '@builder.io/qwik' ;
1414import { KeyCode } from '../../utils/key-code.type' ;
1515import { Behavior } from './behavior.type' ;
16- import { TAB_ID_PREFIX , Tab , TabProps } from './tab' ;
16+ import { Tab , TabProps } from './tab' ;
1717import { TabPanel , TabPanelProps } from './tab-panel' ;
1818import { tabsContextId } from './tabs-context-id' ;
1919import { TabsContext } from './tabs-context.type' ;
@@ -40,8 +40,7 @@ import { TabList } from './tabs-list';
4040 - do we keep all current props (tabId callbacks?)
4141 - shorthand for tab: "label" or "tab"?
4242 - the TODOs
43- - why id and data-tab-id? we don't need any of them
44- *
43+ *
4544 */
4645
4746export type TabsProps = {
@@ -120,7 +119,7 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
120119 let tabListElement : JSXNode | undefined ;
121120 const tabComponents : JSXNode [ ] = [ ] ;
122121 const panelComponents : JSXNode [ ] = [ ] ;
123- const tabs : TabInfo [ ] = [ ] ;
122+ const tabsInfo : TabInfo [ ] = [ ] ;
124123 let panelIndex = 0 ;
125124 let selectedIndex ;
126125
@@ -156,7 +155,8 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
156155 case TabPanel : {
157156 const { label, selected } = child . props ;
158157 // 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 } ` ;
160160
161161 if ( label ) {
162162 tabComponents . push ( < Tab > { label } </ Tab > ) ;
@@ -173,7 +173,7 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
173173 child . props . _extraClass = panelClass ;
174174
175175 panelComponents . push ( child ) ;
176- tabs . push ( {
176+ tabsInfo . push ( {
177177 tabId,
178178 index : panelIndex ,
179179 panelProps : child . props
@@ -195,11 +195,11 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
195195 }
196196
197197 tabComponents . forEach ( ( tab , index ) => {
198- const tabId = tabs [ index ] ?. tabId ;
198+ const tabId = tabsInfo [ index ] ?. tabId ;
199199 tab . key = tabId ;
200200 tab . props . _tabId = tabId ;
201201 tab . props . _extraClass = tabClass ;
202- tabs [ index ] . tabProps = tab . props ;
202+ tabsInfo [ index ] . tabProps = tab . props ;
203203 } ) ;
204204
205205 if ( tabListElement ) {
@@ -215,7 +215,7 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
215215 }
216216
217217 return (
218- < TabsImpl tabs = { tabs } { ...rest } >
218+ < TabsImpl tabs = { tabsInfo } { ...rest } >
219219 { tabListElement }
220220 { panelComponents }
221221 </ TabsImpl >
@@ -276,6 +276,8 @@ export const TabsImpl = component$((props: TabsProps & { tabs: TabInfo[] }) => {
276276 const selectedTabIdSig = givenTabIdSig || initialSelectedTabIdSig ;
277277
278278 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
279281 const tabs = track ( ( ) => props . tabs ) ;
280282 const tabId = selectedTabIdSig . value ;
281283 updateSignals ( tabs , selectedIndexSig , selectedTabIdSig , { tabId } , true ) ;
@@ -350,15 +352,11 @@ export const TabsImpl = component$((props: TabsProps & { tabs: TabInfo[] }) => {
350352 tab = findPrevEnabledTab ( props . tabs , props . tabs . length ) ;
351353 }
352354 if ( tab ) {
353- focusOnTab ( tab . tabId ) ;
355+ focusOnTab ( tab . index ) ;
354356 }
355357
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 ( ) ;
362360 }
363361 } ) ;
364362
0 commit comments