@react-stately/tabs 3.0.3 → 3.1.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/main.js CHANGED
@@ -1,5 +1,5 @@
1
- var $2jh56$reactstatelylist = require("@react-stately/list");
2
- var $2jh56$react = require("react");
1
+ var $7iSyh$reactstatelylist = require("@react-stately/list");
2
+ var $7iSyh$react = require("react");
3
3
 
4
4
  function $parcel$exportWildcard(dest, source) {
5
5
  Object.keys(source).forEach(function(key) {
@@ -20,34 +20,39 @@ function $parcel$exportWildcard(dest, source) {
20
20
  function $parcel$export(e, n, v, s) {
21
21
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
22
22
  }
23
- var $c990352501f33d9e$exports = {};
23
+ var $817f925d289daf81$exports = {};
24
24
 
25
- $parcel$export($c990352501f33d9e$exports, "useTabListState", () => $c990352501f33d9e$export$4ba071daf4e486);
25
+ $parcel$export($817f925d289daf81$exports, "useTabListState", () => $817f925d289daf81$export$4ba071daf4e486);
26
26
 
27
27
 
28
- function $c990352501f33d9e$export$4ba071daf4e486(props) {
29
- let state = $2jh56$reactstatelylist.useSingleSelectListState({
28
+ function $817f925d289daf81$export$4ba071daf4e486(props) {
29
+ let state = $7iSyh$reactstatelylist.useSingleSelectListState({
30
30
  ...props,
31
31
  suppressTextValueWarning: true
32
32
  });
33
- $2jh56$react.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 = state.selectedKey;
36
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
37
- selectedKey = state.collection.getFirstKey();
38
- state.selectionManager.replaceSelection(selectedKey);
39
- }
40
- if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
41
- }, [
42
- state.selectionManager,
43
- state.selectedKey,
44
- state.collection
45
- ]);
33
+ let { selectionManager: selectionManager , collection: collection , selectedKey: currentSelectedKey } = state;
34
+ let lastSelectedKey = $7iSyh$react.useRef(currentSelectedKey);
35
+ // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
36
+ let selectedKey = currentSelectedKey;
37
+ if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {
38
+ selectedKey = collection.getFirstKey();
39
+ // loop over tabs until we find one that isn't disabled and select that
40
+ while(state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
41
+ // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
42
+ if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
43
+ // directly set selection because replace/toggle selection won't consider disabled keys
44
+ selectionManager.setSelectedKeys([
45
+ selectedKey
46
+ ]);
47
+ }
48
+ // 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.
49
+ if (selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
50
+ lastSelectedKey.current = selectedKey;
46
51
  return state;
47
52
  }
48
53
 
49
54
 
50
- $parcel$exportWildcard(module.exports, $c990352501f33d9e$exports);
55
+ $parcel$exportWildcard(module.exports, $817f925d289daf81$exports);
51
56
 
52
57
 
53
58
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;SCuBgB,uCAAe,CAAmB,KAAsB,EAAmB,CAAC;IAC1F,GAAG,CAAC,KAAK,GAAG,gDAAwB,CAAI,CAAC;WACpC,KAAK;QACR,wBAAwB,EAAE,IAAI;IAChC,CAAC;IAED,sBAAS,KAAO,CAAC;QACf,EAA0H,AAA1H,wHAA0H;QAC1H,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW;QACnC,EAAE,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,KAAK,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,GAAG,CAAC;YAC7E,WAAW,GAAG,KAAK,CAAC,UAAU,CAAC,WAAW;YAC1C,KAAK,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,WAAW;QACrD,CAAC;QAED,EAAE,EAAE,KAAK,CAAC,gBAAgB,CAAC,UAAU,IAAI,IAAI,EAC3C,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,WAAW;IAEpD,CAAC,EAAE,CAAC;QAAA,KAAK,CAAC,gBAAgB;QAAE,KAAK,CAAC,WAAW;QAAE,KAAK,CAAC,UAAU;IAAA,CAAC;IAEhE,MAAM,CAAC,KAAK;AACd,CAAC","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 * 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 {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useEffect} from 'react';\n\n\nexport interface TabListState<T> extends SingleSelectListState<T> {}\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: TabListProps<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n suppressTextValueWarning: true\n });\n\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 = state.selectedKey;\n if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {\n selectedKey = state.collection.getFirstKey();\n state.selectionManager.replaceSelection(selectedKey);\n }\n\n if (state.selectionManager.focusedKey == null) {\n state.selectionManager.setFocusedKey(selectedKey);\n }\n }, [state.selectionManager, state.selectedKey, state.collection]);\n\n return state;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;SCuBgB,uCAAe,CAAmB,KAAsB,EAAmB,CAAC;IAC1F,GAAG,CAAC,KAAK,GAAG,gDAAwB,CAAI,CAAC;WACpC,KAAK;QACR,wBAAwB,EAAE,IAAI;IAChC,CAAC;IAED,GAAG,CAAC,CAAC,mBACH,gBAAgB,eAChB,UAAU,GACV,WAAW,EAAE,kBAAkB,EACjC,CAAC,GAAG,KAAK;IAET,GAAG,CAAC,eAAe,GAAG,mBAAM,CAAC,kBAAkB;IAC/C,EAA0H,AAA1H,wHAA0H;IAC1H,GAAG,CAAC,WAAW,GAAG,kBAAkB;IACpC,EAAE,EAAE,gBAAgB,CAAC,OAAO,KAAK,UAAU,CAAC,OAAO,CAAC,WAAW,GAAG,CAAC;QACjE,WAAW,GAAG,UAAU,CAAC,WAAW;QACpC,EAAuE,AAAvE,qEAAuE;cAChE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,UAAU,CAAC,UAAU,GACjF,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,WAAW;QAElD,EAAoH,AAApH,kHAAoH;QACpH,EAAE,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,UAAU,CAAC,UAAU,IAC9E,WAAW,GAAG,UAAU,CAAC,WAAW;QAEtC,EAAuF,AAAvF,qFAAuF;QACvF,gBAAgB,CAAC,eAAe,CAAC,CAAC;YAAA,WAAW;QAAA,CAAC;IAChD,CAAC;IAED,EAA2J,AAA3J,yJAA2J;IAC3J,EAAE,EAAE,gBAAgB,CAAC,UAAU,IAAI,IAAI,KAAM,gBAAgB,CAAC,SAAS,IAAI,WAAW,KAAK,eAAe,CAAC,OAAO,EAChH,gBAAgB,CAAC,aAAa,CAAC,WAAW;IAE5C,eAAe,CAAC,OAAO,GAAG,WAAW;IAErC,MAAM,CAAC,KAAK;AACd,CAAC","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 * 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 {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useRef} from 'react';\n\n\nexport interface TabListState<T> extends SingleSelectListState<T> {}\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: TabListProps<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 // 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 // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\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 (selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n\n return state;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,37 +1,42 @@
1
- import {useSingleSelectListState as $a9c3b$useSingleSelectListState} from "@react-stately/list";
2
- import {useEffect as $a9c3b$useEffect} from "react";
1
+ import {useSingleSelectListState as $ijHKZ$useSingleSelectListState} from "@react-stately/list";
2
+ import {useRef as $ijHKZ$useRef} from "react";
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
- var $ead76093e5740fb6$exports = {};
7
+ var $76f919a04c5a7d14$exports = {};
8
8
 
9
- $parcel$export($ead76093e5740fb6$exports, "useTabListState", () => $ead76093e5740fb6$export$4ba071daf4e486);
9
+ $parcel$export($76f919a04c5a7d14$exports, "useTabListState", () => $76f919a04c5a7d14$export$4ba071daf4e486);
10
10
 
11
11
 
12
- function $ead76093e5740fb6$export$4ba071daf4e486(props) {
13
- let state = $a9c3b$useSingleSelectListState({
12
+ function $76f919a04c5a7d14$export$4ba071daf4e486(props) {
13
+ let state = $ijHKZ$useSingleSelectListState({
14
14
  ...props,
15
15
  suppressTextValueWarning: true
16
16
  });
17
- $a9c3b$useEffect(()=>{
18
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
19
- let selectedKey = state.selectedKey;
20
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
21
- selectedKey = state.collection.getFirstKey();
22
- state.selectionManager.replaceSelection(selectedKey);
23
- }
24
- if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
25
- }, [
26
- state.selectionManager,
27
- state.selectedKey,
28
- state.collection
29
- ]);
17
+ let { selectionManager: selectionManager , collection: collection , selectedKey: currentSelectedKey } = state;
18
+ let lastSelectedKey = $ijHKZ$useRef(currentSelectedKey);
19
+ // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
20
+ let selectedKey = currentSelectedKey;
21
+ if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {
22
+ selectedKey = collection.getFirstKey();
23
+ // loop over tabs until we find one that isn't disabled and select that
24
+ while(state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
25
+ // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
26
+ if (state.disabledKeys.has(selectedKey) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
27
+ // directly set selection because replace/toggle selection won't consider disabled keys
28
+ selectionManager.setSelectedKeys([
29
+ selectedKey
30
+ ]);
31
+ }
32
+ // 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.
33
+ if (selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
34
+ lastSelectedKey.current = selectedKey;
30
35
  return state;
31
36
  }
32
37
 
33
38
 
34
39
 
35
40
 
36
- export {$ead76093e5740fb6$export$4ba071daf4e486 as useTabListState};
41
+ export {$76f919a04c5a7d14$export$4ba071daf4e486 as useTabListState};
37
42
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;SCuBgB,uCAAe,CAAmB,KAAsB,EAAmB,CAAC;IAC1F,GAAG,CAAC,KAAK,GAAG,+BAAwB,CAAI,CAAC;WACpC,KAAK;QACR,wBAAwB,EAAE,IAAI;IAChC,CAAC;IAED,gBAAS,KAAO,CAAC;QACf,EAA0H,AAA1H,wHAA0H;QAC1H,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW;QACnC,EAAE,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,KAAK,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,GAAG,CAAC;YAC7E,WAAW,GAAG,KAAK,CAAC,UAAU,CAAC,WAAW;YAC1C,KAAK,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,WAAW;QACrD,CAAC;QAED,EAAE,EAAE,KAAK,CAAC,gBAAgB,CAAC,UAAU,IAAI,IAAI,EAC3C,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,WAAW;IAEpD,CAAC,EAAE,CAAC;QAAA,KAAK,CAAC,gBAAgB;QAAE,KAAK,CAAC,WAAW;QAAE,KAAK,CAAC,UAAU;IAAA,CAAC;IAEhE,MAAM,CAAC,KAAK;AACd,CAAC","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 * 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 {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useEffect} from 'react';\n\n\nexport interface TabListState<T> extends SingleSelectListState<T> {}\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: TabListProps<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n suppressTextValueWarning: true\n });\n\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 = state.selectedKey;\n if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {\n selectedKey = state.collection.getFirstKey();\n state.selectionManager.replaceSelection(selectedKey);\n }\n\n if (state.selectionManager.focusedKey == null) {\n state.selectionManager.setFocusedKey(selectedKey);\n }\n }, [state.selectionManager, state.selectedKey, state.collection]);\n\n return state;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;;;;;SCuBgB,uCAAe,CAAmB,KAAsB,EAAmB,CAAC;IAC1F,GAAG,CAAC,KAAK,GAAG,+BAAwB,CAAI,CAAC;WACpC,KAAK;QACR,wBAAwB,EAAE,IAAI;IAChC,CAAC;IAED,GAAG,CAAC,CAAC,mBACH,gBAAgB,eAChB,UAAU,GACV,WAAW,EAAE,kBAAkB,EACjC,CAAC,GAAG,KAAK;IAET,GAAG,CAAC,eAAe,GAAG,aAAM,CAAC,kBAAkB;IAC/C,EAA0H,AAA1H,wHAA0H;IAC1H,GAAG,CAAC,WAAW,GAAG,kBAAkB;IACpC,EAAE,EAAE,gBAAgB,CAAC,OAAO,KAAK,UAAU,CAAC,OAAO,CAAC,WAAW,GAAG,CAAC;QACjE,WAAW,GAAG,UAAU,CAAC,WAAW;QACpC,EAAuE,AAAvE,qEAAuE;cAChE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,UAAU,CAAC,UAAU,GACjF,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,WAAW;QAElD,EAAoH,AAApH,kHAAoH;QACpH,EAAE,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,UAAU,CAAC,UAAU,IAC9E,WAAW,GAAG,UAAU,CAAC,WAAW;QAEtC,EAAuF,AAAvF,qFAAuF;QACvF,gBAAgB,CAAC,eAAe,CAAC,CAAC;YAAA,WAAW;QAAA,CAAC;IAChD,CAAC;IAED,EAA2J,AAA3J,yJAA2J;IAC3J,EAAE,EAAE,gBAAgB,CAAC,UAAU,IAAI,IAAI,KAAM,gBAAgB,CAAC,SAAS,IAAI,WAAW,KAAK,eAAe,CAAC,OAAO,EAChH,gBAAgB,CAAC,aAAa,CAAC,WAAW;IAE5C,eAAe,CAAC,OAAO,GAAG,WAAW;IAErC,MAAM,CAAC,KAAK;AACd,CAAC","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 * 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 {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useRef} from 'react';\n\n\nexport interface TabListState<T> extends SingleSelectListState<T> {}\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: TabListProps<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 // 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 // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\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 (selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n\n return state;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;AAiBA,8BAA8B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;CAAG;AAEpE;;;GAGG;AACH,gCAAgC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAoBzF","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 * from './useTabListState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAiBA,8BAA8B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;CAAG;AAEpE;;;GAGG;AACH,gCAAgC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAoCzF","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 * 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.0.3",
3
+ "version": "3.1.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,15 +18,15 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-stately/list": "^3.4.3",
22
- "@react-stately/utils": "^3.4.1",
23
- "@react-types/tabs": "^3.0.3"
21
+ "@react-stately/list": "^3.5.0",
22
+ "@react-stately/utils": "^3.5.0",
23
+ "@react-types/tabs": "^3.1.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "react": "^16.8.0 || ^17.0.0-rc.1"
26
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "404d41859b7d6f56201d7fc01bd9f22ae3512937"
31
+ "gitHead": "8f921ec5094e7c2b3c301bcb6133372e35a2052b"
32
32
  }
@@ -12,7 +12,7 @@
12
12
 
13
13
  import {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';
14
14
  import {TabListProps} from '@react-types/tabs';
15
- import {useEffect} from 'react';
15
+ import {useRef} from 'react';
16
16
 
17
17
 
18
18
  export interface TabListState<T> extends SingleSelectListState<T> {}
@@ -27,18 +27,34 @@ export function useTabListState<T extends object>(props: TabListProps<T>): TabLi
27
27
  suppressTextValueWarning: true
28
28
  });
29
29
 
30
- useEffect(() => {
31
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
32
- let selectedKey = state.selectedKey;
33
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
34
- selectedKey = state.collection.getFirstKey();
35
- state.selectionManager.replaceSelection(selectedKey);
36
- }
30
+ let {
31
+ selectionManager,
32
+ collection,
33
+ selectedKey: currentSelectedKey
34
+ } = state;
37
35
 
38
- if (state.selectionManager.focusedKey == null) {
39
- state.selectionManager.setFocusedKey(selectedKey);
36
+ let lastSelectedKey = useRef(currentSelectedKey);
37
+ // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
38
+ let selectedKey = currentSelectedKey;
39
+ if (selectionManager.isEmpty || !collection.getItem(selectedKey)) {
40
+ selectedKey = collection.getFirstKey();
41
+ // loop over tabs until we find one that isn't disabled and select that
42
+ while (state.disabledKeys.has(selectedKey) && selectedKey !== collection.getLastKey()) {
43
+ selectedKey = collection.getKeyAfter(selectedKey);
44
+ }
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()) {
47
+ selectedKey = collection.getFirstKey();
40
48
  }
41
- }, [state.selectionManager, state.selectedKey, state.collection]);
49
+ // directly set selection because replace/toggle selection won't consider disabled keys
50
+ selectionManager.setSelectedKeys([selectedKey]);
51
+ }
52
+
53
+ // 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.
54
+ if (selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {
55
+ selectionManager.setFocusedKey(selectedKey);
56
+ }
57
+ lastSelectedKey.current = selectedKey;
42
58
 
43
59
  return state;
44
60
  }