Skip to content

Commit fdfa104

Browse files
authored
fix(tabs): recalculate indicator styles on resize (#458)
1 parent 23d90f1 commit fdfa104

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

packages/core/package.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
},
2525
"license": "MIT",
2626
"author": "jer3m01 <[email protected]>",
27-
"contributors": [
28-
"Fabien Marie-Louise <[email protected]>"
29-
],
27+
"contributors": ["Fabien Marie-Louise <[email protected]>"],
3028
"sideEffects": false,
3129
"type": "module",
3230
"exports": {
@@ -47,18 +45,11 @@
4745
"types": "dist/index.d.ts",
4846
"typesVersions": {
4947
"*": {
50-
"*": [
51-
"./dist/*/index.d.ts",
52-
"./dist/index.d.ts"
53-
]
48+
"*": ["./dist/*/index.d.ts", "./dist/index.d.ts"]
5449
}
5550
},
5651
"source": "src/index.tsx",
57-
"files": [
58-
"dist",
59-
"src",
60-
"NOTICE.txt"
61-
],
52+
"files": ["dist", "src", "NOTICE.txt"],
6253
"scripts": {
6354
"build": "pnpm build:cp && pnpm build:tsup",
6455
"build:cp": "cp ../../NOTICE.txt .",
@@ -75,11 +66,12 @@
7566
"@internationalized/number": "^3.2.1",
7667
"@kobalte/utils": "^0.9.0",
7768
"@solid-primitives/props": "^3.1.8",
69+
"@solid-primitives/resize-observer": "^2.0.26",
7870
"solid-presence": "^0.1.6",
7971
"solid-prevent-scroll": "^0.1.4"
8072
},
8173
"devDependencies": {
82-
"@kobalte/tests": "^0.6.0",
74+
"@kobalte/tests": "workspace:*",
8375
"esbuild-plugin-solid": "^0.5.0",
8476
"tsup": "7.2.0"
8577
},

packages/core/src/tabs/tabs-indicator.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717

1818
import type { Orientation } from "@kobalte/utils";
1919
import { combineStyle } from "@solid-primitives/props";
20+
import { createResizeObserver } from "@solid-primitives/resize-observer";
2021
import { useLocale } from "../i18n";
2122
import {
2223
type ElementOf,
@@ -114,12 +115,36 @@ export function TabsIndicator<T extends ValidComponent = "div">(
114115
),
115116
);
116117

118+
const [resizing, setResizing] = createSignal(false);
119+
120+
let timeout: NodeJS.Timeout | null = null;
121+
let prevTarget: any = null;
122+
createResizeObserver(context.selectedTab, (_, t) => {
123+
if (prevTarget !== t) {
124+
prevTarget = t;
125+
return;
126+
}
127+
128+
setResizing(true);
129+
130+
if (timeout) clearTimeout(timeout);
131+
132+
// gives the browser a chance to skip any animations that are disabled while resizing
133+
timeout = setTimeout(() => {
134+
timeout = null;
135+
setResizing(false);
136+
}, 1);
137+
138+
computeStyle();
139+
});
140+
117141
return (
118142
<Polymorphic<TabsIndicatorRenderProps>
119143
as="div"
120144
role="presentation"
121145
style={combineStyle(style(), local.style)}
122146
data-orientation={context.orientation()}
147+
data-resizing={resizing()}
123148
{...others}
124149
/>
125150
);

pnpm-lock.yaml

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)