@theguild/components 9.12.0-alpha-20251204002326-2a985828907ff904a08269604e8ed510d0fd16c4 → 9.12.0-alpha-20251204140849-33f2cded35360019d44f4277a3dc63b6799e421e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,8 +16,12 @@ interface TabsProps extends Pick<TabGroupProps, 'defaultIndex' | 'selectedIndex'
16
16
  * @default "tab"
17
17
  */
18
18
  searchParamKey?: string;
19
- /** LocalStorage key for persisting the selected tab. */
20
- storageKey?: string;
19
+ /**
20
+ * LocalStorage key for persisting the selected tab.
21
+ * Defaults to `tabs-${id}` if not provided.
22
+ * Set to `null` to disable localStorage persistence.
23
+ */
24
+ storageKey?: string | null;
21
25
  /** Tabs CSS class name. */
22
26
  className?: TabListProps['className'];
23
27
  /** Tab CSS class name. */
@@ -33,7 +33,9 @@ const Tabs = ({
33
33
  tabClassName
34
34
  }) => {
35
35
  const id = useId();
36
- storageKey ??= `tabs-${id}`;
36
+ if (storageKey === void 0) {
37
+ storageKey = `tabs-${id}`;
38
+ }
37
39
  let [selectedIndex, setSelectedIndex] = useState(defaultIndex);
38
40
  if (_selectedIndex !== void 0) {
39
41
  selectedIndex = _selectedIndex;
@@ -58,7 +60,16 @@ const Tabs = ({
58
60
  }
59
61
  if (searchParamKey) {
60
62
  const searchParams = new URLSearchParams(window.location.search);
61
- searchParams.set(searchParamKey, getTabKey(items, index, id));
63
+ const tabKeys = new Set(searchParams.getAll(searchParamKey));
64
+ for (let i = 0; i < items.length; i++) {
65
+ const key = getTabKey(items, i, id);
66
+ tabKeys.delete(key);
67
+ }
68
+ searchParams.delete(searchParamKey);
69
+ for (const key of tabKeys) {
70
+ searchParams.append(searchParamKey, key);
71
+ }
72
+ searchParams.append(searchParamKey, getTabKey(items, index, id));
62
73
  window.history.replaceState(
63
74
  null,
64
75
  "",
@@ -138,6 +149,13 @@ function useActiveTabFromURL(tabPanelsRef, items, searchParamKey, setSelectedInd
138
149
  const tabIndexFromSearchParams = items.findIndex(
139
150
  (_, index) => tabsInSearchParams.includes(getTabKey(items, index, id))
140
151
  );
152
+ console.log({
153
+ searchParams,
154
+ tabIndexFromSearchParams,
155
+ tabsInSearchParams,
156
+ items,
157
+ id
158
+ });
141
159
  useIsomorphicLayoutEffect(() => {
142
160
  const tabPanel = hash ? tabPanelsRef.current?.querySelector(`[role=tabpanel]:has([id="${hash}"])`) : null;
143
161
  if (tabPanel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theguild/components",
3
- "version": "9.12.0-alpha-20251204002326-2a985828907ff904a08269604e8ed510d0fd16c4",
3
+ "version": "9.12.0-alpha-20251204140849-33f2cded35360019d44f4277a3dc63b6799e421e",
4
4
  "repository": {
5
5
  "url": "https://github.com/the-guild-org/docs",
6
6
  "directory": "packages/components"