@react-stately/tabs 3.4.1 → 3.5.0
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.
- package/dist/import.mjs +19 -17
- package/dist/main.js +18 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +19 -17
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/useTabListState.ts +23 -21
package/dist/import.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useSingleSelectListState as $ijHKZ$useSingleSelectListState} from "@react-stately/list";
|
|
2
|
-
import {useRef as $ijHKZ$useRef} from "react";
|
|
2
|
+
import {useRef as $ijHKZ$useRef, useEffect as $ijHKZ$useEffect} from "react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -30,22 +30,24 @@ function $76f919a04c5a7d14$export$4ba071daf4e486(props) {
|
|
|
30
30
|
});
|
|
31
31
|
let { selectionManager: selectionManager , collection: collection , selectedKey: currentSelectedKey } = state;
|
|
32
32
|
let lastSelectedKey = (0, $ijHKZ$useRef)(currentSelectedKey);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
(0, $ijHKZ$useEffect)(()=>{
|
|
34
|
+
// Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
|
|
35
|
+
let selectedKey = currentSelectedKey;
|
|
36
|
+
if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {
|
|
37
|
+
selectedKey = collection.getFirstKey();
|
|
38
|
+
// loop over tabs until we find one that isn't disabled and select that
|
|
39
|
+
while(state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
|
|
40
|
+
// if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
|
|
41
|
+
if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
|
|
42
|
+
if (selectedKey != null) // directly set selection because replace/toggle selection won't consider disabled keys
|
|
43
|
+
selectionManager.setSelectedKeys([
|
|
44
|
+
selectedKey
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
// If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
|
|
48
|
+
if (selectedKey != null && selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
|
|
49
|
+
lastSelectedKey.current = selectedKey;
|
|
50
|
+
});
|
|
49
51
|
return {
|
|
50
52
|
...state,
|
|
51
53
|
isDisabled: props.isDisabled || false
|
package/dist/main.js
CHANGED
|
@@ -35,22 +35,24 @@ function $817f925d289daf81$export$4ba071daf4e486(props) {
|
|
|
35
35
|
});
|
|
36
36
|
let { selectionManager: selectionManager , collection: collection , selectedKey: currentSelectedKey } = state;
|
|
37
37
|
let lastSelectedKey = (0, $7iSyh$react.useRef)(currentSelectedKey);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
(0, $7iSyh$react.useEffect)(()=>{
|
|
39
|
+
// Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
|
|
40
|
+
let selectedKey = currentSelectedKey;
|
|
41
|
+
if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {
|
|
42
|
+
selectedKey = collection.getFirstKey();
|
|
43
|
+
// loop over tabs until we find one that isn't disabled and select that
|
|
44
|
+
while(state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
|
|
45
|
+
// if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
|
|
46
|
+
if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
|
|
47
|
+
if (selectedKey != null) // directly set selection because replace/toggle selection won't consider disabled keys
|
|
48
|
+
selectionManager.setSelectedKeys([
|
|
49
|
+
selectedKey
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
// If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
|
|
53
|
+
if (selectedKey != null && selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
|
|
54
|
+
lastSelectedKey.current = selectedKey;
|
|
55
|
+
});
|
|
54
56
|
return {
|
|
55
57
|
...state,
|
|
56
58
|
isDisabled: props.isDisabled || false
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AAkBM,SAAS,wCAAkC,KAA6B;IAC7E,IAAI,QAAQ,CAAA,GAAA,gDAAuB,EAAK;QACtC,GAAG,KAAK;QACR,0BAA0B;IAC5B;IAEA,IAAI,oBACF,iBAAgB,cAChB,WAAU,EACV,aAAa,mBAAkB,EAChC,GAAG;IAEJ,IAAI,kBAAkB,CAAA,GAAA,mBAAK,EAAE;IAC7B,CAAA,GAAA,sBAAQ,EAAE;QACR,0HAA0H;QAC1H,IAAI,cAAc;QAClB,IAAI,iBAAiB,WAAW,CAAC,WAAW,QAAQ,cAAc;YAChE,cAAc,WAAW;YACzB,uEAAuE;YACvE,MAAO,MAAM,aAAa,IAAI,gBAAgB,gBAAgB,WAAW,aACvE,cAAc,WAAW,YAAY;YAEvC,oHAAoH;YACpH,IAAI,MAAM,aAAa,IAAI,gBAAgB,gBAAgB,WAAW,cACpE,cAAc,WAAW;YAG3B,IAAI,eAAe,MACjB,uFAAuF;YACvF,iBAAiB,gBAAgB;gBAAC;aAAY;QAElD;QAEA,2JAA2J;QAC3J,IAAI,eAAe,QAAQ,iBAAiB,cAAc,QAAS,CAAC,iBAAiB,aAAa,gBAAgB,gBAAgB,SAChI,iBAAiB,cAAc;QAEjC,gBAAgB,UAAU;IAC5B;IAEA,OAAO;QACL,GAAG,KAAK;QACR,YAAY,MAAM,cAAc;IAClC;AACF;;CD9DC","sources":["packages/@react-stately/tabs/src/index.ts","packages/@react-stately/tabs/src/useTabListState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useTabListState} from './useTabListState';\n\nexport type {TabListProps} from '@react-types/tabs';\nexport type {TabListStateOptions, TabListState} from './useTabListState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionStateBase} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n suppressTextValueWarning: true\n });\n\n let {\n selectionManager,\n collection,\n selectedKey: currentSelectedKey\n } = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey()) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) {\n selectedKey = collection.getFirstKey();\n }\n\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useSingleSelectListState as $ijHKZ$useSingleSelectListState} from "@react-stately/list";
|
|
2
|
-
import {useRef as $ijHKZ$useRef} from "react";
|
|
2
|
+
import {useRef as $ijHKZ$useRef, useEffect as $ijHKZ$useEffect} from "react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -30,22 +30,24 @@ function $76f919a04c5a7d14$export$4ba071daf4e486(props) {
|
|
|
30
30
|
});
|
|
31
31
|
let { selectionManager: selectionManager , collection: collection , selectedKey: currentSelectedKey } = state;
|
|
32
32
|
let lastSelectedKey = (0, $ijHKZ$useRef)(currentSelectedKey);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
(0, $ijHKZ$useEffect)(()=>{
|
|
34
|
+
// Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
|
|
35
|
+
let selectedKey = currentSelectedKey;
|
|
36
|
+
if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {
|
|
37
|
+
selectedKey = collection.getFirstKey();
|
|
38
|
+
// loop over tabs until we find one that isn't disabled and select that
|
|
39
|
+
while(state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
|
|
40
|
+
// if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
|
|
41
|
+
if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
|
|
42
|
+
if (selectedKey != null) // directly set selection because replace/toggle selection won't consider disabled keys
|
|
43
|
+
selectionManager.setSelectedKeys([
|
|
44
|
+
selectedKey
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
// If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
|
|
48
|
+
if (selectedKey != null && selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
|
|
49
|
+
lastSelectedKey.current = selectedKey;
|
|
50
|
+
});
|
|
49
51
|
return {
|
|
50
52
|
...state,
|
|
51
53
|
isDisabled: props.isDisabled || false
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AAkBM,SAAS,wCAAkC,KAA6B;IAC7E,IAAI,QAAQ,CAAA,GAAA,+BAAuB,EAAK;QACtC,GAAG,KAAK;QACR,0BAA0B;IAC5B;IAEA,IAAI,oBACF,iBAAgB,cAChB,WAAU,EACV,aAAa,mBAAkB,EAChC,GAAG;IAEJ,IAAI,kBAAkB,CAAA,GAAA,aAAK,EAAE;IAC7B,CAAA,GAAA,gBAAQ,EAAE;QACR,0HAA0H;QAC1H,IAAI,cAAc;QAClB,IAAI,iBAAiB,WAAW,CAAC,WAAW,QAAQ,cAAc;YAChE,cAAc,WAAW;YACzB,uEAAuE;YACvE,MAAO,MAAM,aAAa,IAAI,gBAAgB,gBAAgB,WAAW,aACvE,cAAc,WAAW,YAAY;YAEvC,oHAAoH;YACpH,IAAI,MAAM,aAAa,IAAI,gBAAgB,gBAAgB,WAAW,cACpE,cAAc,WAAW;YAG3B,IAAI,eAAe,MACjB,uFAAuF;YACvF,iBAAiB,gBAAgB;gBAAC;aAAY;QAElD;QAEA,2JAA2J;QAC3J,IAAI,eAAe,QAAQ,iBAAiB,cAAc,QAAS,CAAC,iBAAiB,aAAa,gBAAgB,gBAAgB,SAChI,iBAAiB,cAAc;QAEjC,gBAAgB,UAAU;IAC5B;IAEA,OAAO;QACL,GAAG,KAAK;QACR,YAAY,MAAM,cAAc;IAClC;AACF;;CD9DC","sources":["packages/@react-stately/tabs/src/index.ts","packages/@react-stately/tabs/src/useTabListState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useTabListState} from './useTabListState';\n\nexport type {TabListProps} from '@react-types/tabs';\nexport type {TabListStateOptions, TabListState} from './useTabListState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionStateBase} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n suppressTextValueWarning: true\n });\n\n let {\n selectionManager,\n collection,\n selectedKey: currentSelectedKey\n } = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey()) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) {\n selectedKey = collection.getFirstKey();\n }\n\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAiBA,qCAAqC,CAAC,CAAE,SAAQ,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;CAAG;AAE5G,8BAA8B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;IAC/D,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;GAGG;AACH,gCAAgC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,
|
|
1
|
+
{"mappings":";;;AAiBA,qCAAqC,CAAC,CAAE,SAAQ,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;CAAG;AAE5G,8BAA8B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;IAC/D,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;GAGG;AACH,gCAAgC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CA4ChG;AC1DD,YAAY,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC","sources":["packages/@react-stately/tabs/src/packages/@react-stately/tabs/src/useTabListState.ts","packages/@react-stately/tabs/src/packages/@react-stately/tabs/src/index.ts","packages/@react-stately/tabs/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useTabListState} from './useTabListState';\n\nexport type {TabListProps} from '@react-types/tabs';\nexport type {TabListStateOptions, TabListState} from './useTabListState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/tabs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/list": "^3.
|
|
26
|
-
"@react-stately/utils": "^3.
|
|
25
|
+
"@react-stately/list": "^3.9.0",
|
|
26
|
+
"@react-stately/utils": "^3.7.0",
|
|
27
27
|
"@react-types/shared": "^3.18.1",
|
|
28
28
|
"@react-types/tabs": "^3.3.0",
|
|
29
|
-
"@swc/helpers": "^0.
|
|
29
|
+
"@swc/helpers": "^0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "504e40e0a50c1b20ed0fb3ba9561a263b6d5565e"
|
|
38
38
|
}
|
package/src/useTabListState.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import {CollectionStateBase} from '@react-types/shared';
|
|
14
14
|
import {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';
|
|
15
15
|
import {TabListProps} from '@react-types/tabs';
|
|
16
|
-
import {useRef} from 'react';
|
|
16
|
+
import {useEffect, useRef} from 'react';
|
|
17
17
|
|
|
18
18
|
export interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}
|
|
19
19
|
|
|
@@ -39,30 +39,32 @@ export function useTabListState<T extends object>(props: TabListStateOptions<T>)
|
|
|
39
39
|
} = state;
|
|
40
40
|
|
|
41
41
|
let lastSelectedKey = useRef(currentSelectedKey);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// loop over tabs until we find one that isn't disabled and select that
|
|
47
|
-
while (state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey()) {
|
|
48
|
-
selectedKey = collection.getKeyAfter(selectedKey);
|
|
49
|
-
}
|
|
50
|
-
// if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
|
|
51
|
-
if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) {
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
// Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
|
|
44
|
+
let selectedKey = currentSelectedKey;
|
|
45
|
+
if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {
|
|
52
46
|
selectedKey = collection.getFirstKey();
|
|
53
|
-
|
|
47
|
+
// loop over tabs until we find one that isn't disabled and select that
|
|
48
|
+
while (state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey()) {
|
|
49
|
+
selectedKey = collection.getKeyAfter(selectedKey);
|
|
50
|
+
}
|
|
51
|
+
// if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
|
|
52
|
+
if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) {
|
|
53
|
+
selectedKey = collection.getFirstKey();
|
|
54
|
+
}
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
if (selectedKey != null) {
|
|
57
|
+
// directly set selection because replace/toggle selection won't consider disabled keys
|
|
58
|
+
selectionManager.setSelectedKeys([selectedKey]);
|
|
59
|
+
}
|
|
58
60
|
}
|
|
59
|
-
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
// If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
|
|
63
|
+
if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {
|
|
64
|
+
selectionManager.setFocusedKey(selectedKey);
|
|
65
|
+
}
|
|
66
|
+
lastSelectedKey.current = selectedKey;
|
|
67
|
+
});
|
|
66
68
|
|
|
67
69
|
return {
|
|
68
70
|
...state,
|