Skip to content

Commit c5621a5

Browse files
committed
fix(headless/tabs): restored dynamic handling
1 parent 8309d7b commit c5621a5

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/kit-headless/src/components/tabs/tab.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@builder.io/qwik';
1212
import { tabsContextId } from './tabs-context-id';
1313
import { KeyCode } from '../../utils/key-code.type';
14-
import { isServer } from '@builder.io/qwik/build';
14+
import { isBrowser, isServer } from '@builder.io/qwik/build';
1515

1616
export interface TabProps {
1717
onClick?: PropFunction<() => void>;
@@ -26,12 +26,18 @@ export const Tab = component$((props: TabProps) => {
2626
const serverAssignedIndexSig = useSignal<number | undefined>(undefined);
2727
const uniqueId = useId();
2828

29-
useTask$(() => {
29+
useTask$(({ cleanup }) => {
3030
if (isServer) {
3131
serverAssignedIndexSig.value =
3232
contextService.lastAssignedTabIndexSig.value;
3333
contextService.lastAssignedTabIndexSig.value++;
3434
}
35+
if (isBrowser) {
36+
contextService.onTabsChanged$();
37+
}
38+
cleanup(() => {
39+
contextService.onTabsChanged$();
40+
});
3541
});
3642

3743
useTask$(({ track }) => {

packages/kit-headless/src/components/tabs/tabs-panel.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useSignal,
99
} from '@builder.io/qwik';
1010
import { tabsContextId } from './tabs-context-id';
11-
import { isServer } from '@builder.io/qwik/build';
11+
import { isBrowser, isServer } from '@builder.io/qwik/build';
1212

1313
export interface TabPanelProps {
1414
class?: string;
@@ -25,12 +25,18 @@ export const TabPanel = component$(({ ...props }: TabPanelProps) => {
2525
() => contextService.tabPanelsMap[panelUID]?.tabId
2626
);
2727

28-
useTask$(() => {
28+
useTask$(({ cleanup }) => {
2929
if (isServer) {
3030
serverAssignedIndexSig.value =
3131
contextService.lastAssignedPanelIndexSig.value;
3232
contextService.lastAssignedPanelIndexSig.value++;
3333
}
34+
if (isBrowser) {
35+
contextService.onTabsChanged$();
36+
}
37+
cleanup(() => {
38+
contextService.onTabsChanged$();
39+
});
3440
});
3541

3642
const isSelectedSignal = useComputed$(() => {

0 commit comments

Comments
 (0)