@react-stately/tabs 3.0.1 → 3.0.4

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,40 +1,51 @@
1
- var {
2
- useEffect
3
- } = require("react");
1
+ var $7iSyh$reactstatelylist = require("@react-stately/list");
2
+ var $7iSyh$react = require("react");
4
3
 
5
- var {
6
- useSingleSelectListState
7
- } = require("@react-stately/list");
4
+ function $parcel$exportWildcard(dest, source) {
5
+ Object.keys(source).forEach(function(key) {
6
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
7
+ return;
8
+ }
8
9
 
9
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
10
+ Object.defineProperty(dest, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return source[key];
14
+ }
15
+ });
16
+ });
10
17
 
11
- function $parcel$interopDefault(a) {
12
- return a && a.__esModule ? a.default : a;
18
+ return dest;
19
+ }
20
+ function $parcel$export(e, n, v, s) {
21
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
13
22
  }
23
+ var $817f925d289daf81$exports = {};
14
24
 
15
- /**
16
- * Provides state management for a Tabs component. Tabs include a TabList which tracks
17
- * which tab is currently selected and displays the content associated with that Tab in a TabPanel.
18
- */
19
- function useTabListState(props) {
20
- let state = useSingleSelectListState(_babelRuntimeHelpersExtends({}, props, {
21
- suppressTextValueWarning: true
22
- }));
23
- useEffect(() => {
24
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
25
- let selectedKey = state.selectedKey;
25
+ $parcel$export($817f925d289daf81$exports, "useTabListState", () => $817f925d289daf81$export$4ba071daf4e486);
26
26
 
27
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
28
- selectedKey = state.collection.getFirstKey();
29
- state.selectionManager.replaceSelection(selectedKey);
30
- }
31
27
 
32
- if (state.selectionManager.focusedKey == null) {
33
- state.selectionManager.setFocusedKey(selectedKey);
28
+ function $817f925d289daf81$export$4ba071daf4e486(props) {
29
+ let state = $7iSyh$reactstatelylist.useSingleSelectListState({
30
+ ...props,
31
+ suppressTextValueWarning: true
32
+ });
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
+ selectionManager.replaceSelection(selectedKey);
34
40
  }
35
- }, [state.selectionManager, state.selectedKey, state.collection]);
36
- return state;
41
+ // 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.
42
+ if (selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
43
+ lastSelectedKey.current = selectedKey;
44
+ return state;
37
45
  }
38
46
 
39
- exports.useTabListState = useTabListState;
47
+
48
+ $parcel$exportWildcard(module.exports, $817f925d289daf81$exports);
49
+
50
+
40
51
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;ACiBD;;;;AAIO,SAASG,eAAT,CAA2CC,KAA3C,EAAoF;AACzF,MAAIC,KAAK,GAAGC,wBAAwB,iCAC/BF,KAD+B;AAElCG,IAAAA,wBAAwB,EAAE;AAFQ,KAApC;AAKAC,EAAAA,SAAS,CAAC,MAAM;AACd;AACA,QAAIC,WAAW,GAAGJ,KAAK,CAACI,WAAxB;;AACA,QAAIJ,KAAK,CAACK,gBAAN,CAAuBC,OAAvB,IAAkC,CAACN,KAAK,CAACO,UAAN,CAAiBC,OAAjB,CAAyBJ,WAAzB,CAAvC,EAA8E;AAC5EA,MAAAA,WAAW,GAAGJ,KAAK,CAACO,UAAN,CAAiBE,WAAjB,EAAd;AACAT,MAAAA,KAAK,CAACK,gBAAN,CAAuBK,gBAAvB,CAAwCN,WAAxC;AACD;;AAED,QAAIJ,KAAK,CAACK,gBAAN,CAAuBM,UAAvB,IAAqC,IAAzC,EAA+C;AAC7CX,MAAAA,KAAK,CAACK,gBAAN,CAAuBO,aAAvB,CAAqCR,WAArC;AACD;AACF,GAXQ,EAWN,CAACJ,KAAK,CAACK,gBAAP,EAAyBL,KAAK,CAACI,WAA/B,EAA4CJ,KAAK,CAACO,UAAlD,CAXM,CAAT;AAaA,SAAOP,KAAP;AACD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-stately/tabs/src/useTabListState.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\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":["$parcel$interopDefault","a","__esModule","default","useTabListState","props","state","useSingleSelectListState","suppressTextValueWarning","useEffect","selectedKey","selectionManager","isEmpty","collection","getItem","getFirstKey","replaceSelection","focusedKey","setFocusedKey"],"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,gBAAgB,CAAC,gBAAgB,CAAC,WAAW;IAC/C,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 selectionManager.replaceSelection(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,28 +1,35 @@
1
- import { useEffect } from "react";
2
- import { useSingleSelectListState } from "@react-stately/list";
3
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
4
-
5
- /**
6
- * Provides state management for a Tabs component. Tabs include a TabList which tracks
7
- * which tab is currently selected and displays the content associated with that Tab in a TabPanel.
8
- */
9
- export function useTabListState(props) {
10
- let state = useSingleSelectListState(_babelRuntimeHelpersEsmExtends({}, props, {
11
- suppressTextValueWarning: true
12
- }));
13
- useEffect(() => {
14
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
15
- let selectedKey = state.selectedKey;
1
+ import {useSingleSelectListState as $ijHKZ$useSingleSelectListState} from "@react-stately/list";
2
+ import {useRef as $ijHKZ$useRef} from "react";
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+ var $76f919a04c5a7d14$exports = {};
8
+
9
+ $parcel$export($76f919a04c5a7d14$exports, "useTabListState", () => $76f919a04c5a7d14$export$4ba071daf4e486);
16
10
 
17
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
18
- selectedKey = state.collection.getFirstKey();
19
- state.selectionManager.replaceSelection(selectedKey);
20
- }
21
11
 
22
- if (state.selectionManager.focusedKey == null) {
23
- state.selectionManager.setFocusedKey(selectedKey);
12
+ function $76f919a04c5a7d14$export$4ba071daf4e486(props) {
13
+ let state = $ijHKZ$useSingleSelectListState({
14
+ ...props,
15
+ suppressTextValueWarning: true
16
+ });
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
+ selectionManager.replaceSelection(selectedKey);
24
24
  }
25
- }, [state.selectionManager, state.selectedKey, state.collection]);
26
- return state;
25
+ // 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.
26
+ if (selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
27
+ lastSelectedKey.current = selectedKey;
28
+ return state;
27
29
  }
30
+
31
+
32
+
33
+
34
+ export {$76f919a04c5a7d14$export$4ba071daf4e486 as useTabListState};
28
35
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;AAmBA;;;;OAIO,SAASA,eAAT,CAA2CC,KAA3C,EAAoF;AACzF,MAAIC,KAAK,GAAGC,wBAAwB,oCAC/BF,KAD+B;AAElCG,IAAAA,wBAAwB,EAAE;AAFQ,KAApC;AAKAC,EAAAA,SAAS,CAAC,MAAM;AACd;AACA,QAAIC,WAAW,GAAGJ,KAAK,CAACI,WAAxB;;AACA,QAAIJ,KAAK,CAACK,gBAAN,CAAuBC,OAAvB,IAAkC,CAACN,KAAK,CAACO,UAAN,CAAiBC,OAAjB,CAAyBJ,WAAzB,CAAvC,EAA8E;AAC5EA,MAAAA,WAAW,GAAGJ,KAAK,CAACO,UAAN,CAAiBE,WAAjB,EAAd;AACAT,MAAAA,KAAK,CAACK,gBAAN,CAAuBK,gBAAvB,CAAwCN,WAAxC;AACD;;AAED,QAAIJ,KAAK,CAACK,gBAAN,CAAuBM,UAAvB,IAAqC,IAAzC,EAA+C;AAC7CX,MAAAA,KAAK,CAACK,gBAAN,CAAuBO,aAAvB,CAAqCR,WAArC;AACD;AACF,GAXQ,EAWN,CAACJ,KAAK,CAACK,gBAAP,EAAyBL,KAAK,CAACI,WAA/B,EAA4CJ,KAAK,CAACO,UAAlD,CAXM,CAAT;AAaA,SAAOP,KAAP;AACD","sources":["./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\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":["useTabListState","props","state","useSingleSelectListState","suppressTextValueWarning","useEffect","selectedKey","selectionManager","isEmpty","collection","getItem","getFirstKey","replaceSelection","focusedKey","setFocusedKey"],"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,gBAAgB,CAAC,gBAAgB,CAAC,WAAW;IAC/C,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 selectionManager.replaceSelection(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":"A;A;AAiBA,8BAA8B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;CAAG;AAEpE;A;A;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"],"sourcesContent":[null,null],"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,CA2BzF","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.1",
3
+ "version": "3.0.4",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-stately/list": "^3.3.0",
22
- "@react-stately/utils": "^3.2.2",
23
- "@react-types/tabs": "^3.0.1"
21
+ "@react-stately/list": "^3.4.4",
22
+ "@react-stately/utils": "^3.4.1",
23
+ "@react-types/tabs": "^3.0.4"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -28,5 +28,5 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "9204e1b8cb61dac767e91087fb16203611dc67c5"
31
+ "gitHead": "ed8d8d984c2f7f2c31e8b18795b97858a95e4729"
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,25 @@ 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
- }
37
-
38
- if (state.selectionManager.focusedKey == null) {
39
- state.selectionManager.setFocusedKey(selectedKey);
40
- }
41
- }, [state.selectionManager, state.selectedKey, state.collection]);
30
+ let {
31
+ selectionManager,
32
+ collection,
33
+ selectedKey: currentSelectedKey
34
+ } = state;
35
+
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
+ selectionManager.replaceSelection(selectedKey);
42
+ }
43
+
44
+ // 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.
45
+ if (selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {
46
+ selectionManager.setFocusedKey(selectedKey);
47
+ }
48
+ lastSelectedKey.current = selectedKey;
42
49
 
43
50
  return state;
44
51
  }