@react-stately/select 3.6.12 → 3.6.13
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/types.d.ts.map +1 -1
- package/dist/useSelectState.main.js +8 -2
- package/dist/useSelectState.main.js.map +1 -1
- package/dist/useSelectState.mjs +9 -3
- package/dist/useSelectState.module.js +9 -3
- package/dist/useSelectState.module.js.map +1 -1
- package/package.json +7 -7
- package/src/useSelectState.ts +4 -3
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAmBA,oCAAoC,CAAC,CAAE,SAAQ,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;CAAG;AAE1G,6BAA6B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC,EAAE,mBAAmB,EAAE,mBAAmB;IACxG,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,0CAA0C;IAC1C,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAErC,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAE7C,sBAAsB;IACtB,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC;IAEjD,wBAAwB;IACxB,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAAA;CACnD;AAED;;;;GAIG;AACH,+BAA+B,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,
|
|
1
|
+
{"mappings":";;;;;AAmBA,oCAAoC,CAAC,CAAE,SAAQ,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;CAAG;AAE1G,6BAA6B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC,EAAE,mBAAmB,EAAE,mBAAmB;IACxG,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,0CAA0C;IAC1C,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAErC,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAE7C,sBAAsB;IACtB,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC;IAEjD,wBAAwB;IACxB,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAAA;CACnD;AAED;;;;GAIG;AACH,+BAA+B,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CA4C7F;ACzED,YAAY,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-stately/select/src/packages/@react-stately/select/src/useSelectState.ts","packages/@react-stately/select/src/packages/@react-stately/select/src/index.ts","packages/@react-stately/select/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 {useSelectState} from './useSelectState';\n\nexport type {SelectProps} from '@react-types/select';\nexport type {SelectState, SelectStateOptions} from './useSelectState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -39,6 +39,12 @@ function $80ebb60e77198879$export$5159ec8b34d4ec12(props) {
|
|
|
39
39
|
value: listState.selectedKey
|
|
40
40
|
});
|
|
41
41
|
let [isFocused, setFocused] = (0, $5KJtg$react.useState)(false);
|
|
42
|
+
let isEmpty = (0, $5KJtg$react.useMemo)(()=>{
|
|
43
|
+
var _listState_collection_getItem;
|
|
44
|
+
return listState.collection.size === 0 || listState.collection.size === 1 && ((_listState_collection_getItem = listState.collection.getItem(listState.collection.getFirstKey())) === null || _listState_collection_getItem === void 0 ? void 0 : _listState_collection_getItem.type) === 'loader';
|
|
45
|
+
}, [
|
|
46
|
+
listState.collection
|
|
47
|
+
]);
|
|
42
48
|
return {
|
|
43
49
|
...validationState,
|
|
44
50
|
...listState,
|
|
@@ -46,13 +52,13 @@ function $80ebb60e77198879$export$5159ec8b34d4ec12(props) {
|
|
|
46
52
|
focusStrategy: focusStrategy,
|
|
47
53
|
open (focusStrategy = null) {
|
|
48
54
|
// Don't open if the collection is empty.
|
|
49
|
-
if (
|
|
55
|
+
if (!isEmpty) {
|
|
50
56
|
setFocusStrategy(focusStrategy);
|
|
51
57
|
triggerState.open();
|
|
52
58
|
}
|
|
53
59
|
},
|
|
54
60
|
toggle (focusStrategy = null) {
|
|
55
|
-
if (
|
|
61
|
+
if (!isEmpty) {
|
|
56
62
|
setFocusStrategy(focusStrategy);
|
|
57
63
|
triggerState.toggle();
|
|
58
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAiC,KAA4B;IAC3E,IAAI,eAAe,CAAA,GAAA,kDAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAwB;IACvE,IAAI,YAAY,CAAA,GAAA,gDAAuB,EAAE;QACvC,GAAG,KAAK;QACR,mBAAmB,CAAC;YAClB,IAAI,MAAM,iBAAiB,IAAI,MAC7B,MAAM,iBAAiB,CAAC;YAG1B,aAAa,KAAK;YAClB,gBAAgB,gBAAgB;QAClC;IACF;IAEA,IAAI,kBAAkB,CAAA,GAAA,8CAAqB,EAAE;QAC3C,GAAG,KAAK;QACR,OAAO,UAAU,WAAW;IAC9B;IAEA,IAAI,CAAC,WAAW,WAAW,GAAG,CAAA,GAAA,qBAAO,EAAE;
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAiC,KAA4B;IAC3E,IAAI,eAAe,CAAA,GAAA,kDAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAwB;IACvE,IAAI,YAAY,CAAA,GAAA,gDAAuB,EAAE;QACvC,GAAG,KAAK;QACR,mBAAmB,CAAC;YAClB,IAAI,MAAM,iBAAiB,IAAI,MAC7B,MAAM,iBAAiB,CAAC;YAG1B,aAAa,KAAK;YAClB,gBAAgB,gBAAgB;QAClC;IACF;IAEA,IAAI,kBAAkB,CAAA,GAAA,8CAAqB,EAAE;QAC3C,GAAG,KAAK;QACR,OAAO,UAAU,WAAW;IAC9B;IAEA,IAAI,CAAC,WAAW,WAAW,GAAG,CAAA,GAAA,qBAAO,EAAE;IACvC,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE;YAA6E;eAAvE,UAAU,UAAU,CAAC,IAAI,KAAK,KAAM,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,EAAA,gCAAA,UAAU,UAAU,CAAC,OAAO,CAAC,UAAU,UAAU,CAAC,WAAW,iBAA7D,oDAAA,8BAAmE,IAAI,MAAK;OAAW;QAAC,UAAU,UAAU;KAAC;IAEhN,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,SAAS;QACZ,GAAG,YAAY;uBACf;QACA,MAAK,gBAAsC,IAAI;YAC7C,yCAAyC;YACzC,IAAI,CAAC,SAAS;gBACZ,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,CAAC,SAAS;gBACZ,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF","sources":["packages/@react-stately/select/src/useSelectState.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 {CollectionStateBase, FocusStrategy} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';\nimport {SelectProps} from '@react-types/select';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {useMemo, useState} from 'react';\n\nexport interface SelectStateOptions<T> extends Omit<SelectProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T> extends SingleSelectListState<T>, OverlayTriggerState, FormValidationState {\n /** Whether the select is currently focused. */\n readonly isFocused: boolean,\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void,\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null,\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void,\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T extends object>(props: SelectStateOptions<T>): SelectState<T> {\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let listState = useSingleSelectListState({\n ...props,\n onSelectionChange: (key) => {\n if (props.onSelectionChange != null) {\n props.onSelectionChange(key);\n }\n\n triggerState.close();\n validationState.commitValidation();\n }\n });\n\n let validationState = useFormValidationState({\n ...props,\n value: listState.selectedKey\n });\n\n let [isFocused, setFocused] = useState(false);\n let isEmpty = useMemo(() => listState.collection.size === 0 || (listState.collection.size === 1 && listState.collection.getItem(listState.collection.getFirstKey()!)?.type === 'loader'), [listState.collection]);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (!isEmpty) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (!isEmpty) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n"],"names":[],"version":3,"file":"useSelectState.main.js.map"}
|
package/dist/useSelectState.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useFormValidationState as $6FfNf$useFormValidationState} from "@react-stately/form";
|
|
2
2
|
import {useOverlayTriggerState as $6FfNf$useOverlayTriggerState} from "@react-stately/overlays";
|
|
3
3
|
import {useSingleSelectListState as $6FfNf$useSingleSelectListState} from "@react-stately/list";
|
|
4
|
-
import {useState as $6FfNf$useState} from "react";
|
|
4
|
+
import {useState as $6FfNf$useState, useMemo as $6FfNf$useMemo} from "react";
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -33,6 +33,12 @@ function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
|
33
33
|
value: listState.selectedKey
|
|
34
34
|
});
|
|
35
35
|
let [isFocused, setFocused] = (0, $6FfNf$useState)(false);
|
|
36
|
+
let isEmpty = (0, $6FfNf$useMemo)(()=>{
|
|
37
|
+
var _listState_collection_getItem;
|
|
38
|
+
return listState.collection.size === 0 || listState.collection.size === 1 && ((_listState_collection_getItem = listState.collection.getItem(listState.collection.getFirstKey())) === null || _listState_collection_getItem === void 0 ? void 0 : _listState_collection_getItem.type) === 'loader';
|
|
39
|
+
}, [
|
|
40
|
+
listState.collection
|
|
41
|
+
]);
|
|
36
42
|
return {
|
|
37
43
|
...validationState,
|
|
38
44
|
...listState,
|
|
@@ -40,13 +46,13 @@ function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
|
40
46
|
focusStrategy: focusStrategy,
|
|
41
47
|
open (focusStrategy = null) {
|
|
42
48
|
// Don't open if the collection is empty.
|
|
43
|
-
if (
|
|
49
|
+
if (!isEmpty) {
|
|
44
50
|
setFocusStrategy(focusStrategy);
|
|
45
51
|
triggerState.open();
|
|
46
52
|
}
|
|
47
53
|
},
|
|
48
54
|
toggle (focusStrategy = null) {
|
|
49
|
-
if (
|
|
55
|
+
if (!isEmpty) {
|
|
50
56
|
setFocusStrategy(focusStrategy);
|
|
51
57
|
triggerState.toggle();
|
|
52
58
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useFormValidationState as $6FfNf$useFormValidationState} from "@react-stately/form";
|
|
2
2
|
import {useOverlayTriggerState as $6FfNf$useOverlayTriggerState} from "@react-stately/overlays";
|
|
3
3
|
import {useSingleSelectListState as $6FfNf$useSingleSelectListState} from "@react-stately/list";
|
|
4
|
-
import {useState as $6FfNf$useState} from "react";
|
|
4
|
+
import {useState as $6FfNf$useState, useMemo as $6FfNf$useMemo} from "react";
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -33,6 +33,12 @@ function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
|
33
33
|
value: listState.selectedKey
|
|
34
34
|
});
|
|
35
35
|
let [isFocused, setFocused] = (0, $6FfNf$useState)(false);
|
|
36
|
+
let isEmpty = (0, $6FfNf$useMemo)(()=>{
|
|
37
|
+
var _listState_collection_getItem;
|
|
38
|
+
return listState.collection.size === 0 || listState.collection.size === 1 && ((_listState_collection_getItem = listState.collection.getItem(listState.collection.getFirstKey())) === null || _listState_collection_getItem === void 0 ? void 0 : _listState_collection_getItem.type) === 'loader';
|
|
39
|
+
}, [
|
|
40
|
+
listState.collection
|
|
41
|
+
]);
|
|
36
42
|
return {
|
|
37
43
|
...validationState,
|
|
38
44
|
...listState,
|
|
@@ -40,13 +46,13 @@ function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
|
40
46
|
focusStrategy: focusStrategy,
|
|
41
47
|
open (focusStrategy = null) {
|
|
42
48
|
// Don't open if the collection is empty.
|
|
43
|
-
if (
|
|
49
|
+
if (!isEmpty) {
|
|
44
50
|
setFocusStrategy(focusStrategy);
|
|
45
51
|
triggerState.open();
|
|
46
52
|
}
|
|
47
53
|
},
|
|
48
54
|
toggle (focusStrategy = null) {
|
|
49
|
-
if (
|
|
55
|
+
if (!isEmpty) {
|
|
50
56
|
setFocusStrategy(focusStrategy);
|
|
51
57
|
triggerState.toggle();
|
|
52
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAiC,KAA4B;IAC3E,IAAI,eAAe,CAAA,GAAA,6BAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAwB;IACvE,IAAI,YAAY,CAAA,GAAA,+BAAuB,EAAE;QACvC,GAAG,KAAK;QACR,mBAAmB,CAAC;YAClB,IAAI,MAAM,iBAAiB,IAAI,MAC7B,MAAM,iBAAiB,CAAC;YAG1B,aAAa,KAAK;YAClB,gBAAgB,gBAAgB;QAClC;IACF;IAEA,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,EAAE;QAC3C,GAAG,KAAK;QACR,OAAO,UAAU,WAAW;IAC9B;IAEA,IAAI,CAAC,WAAW,WAAW,GAAG,CAAA,GAAA,eAAO,EAAE;
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAiC,KAA4B;IAC3E,IAAI,eAAe,CAAA,GAAA,6BAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAwB;IACvE,IAAI,YAAY,CAAA,GAAA,+BAAuB,EAAE;QACvC,GAAG,KAAK;QACR,mBAAmB,CAAC;YAClB,IAAI,MAAM,iBAAiB,IAAI,MAC7B,MAAM,iBAAiB,CAAC;YAG1B,aAAa,KAAK;YAClB,gBAAgB,gBAAgB;QAClC;IACF;IAEA,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,EAAE;QAC3C,GAAG,KAAK;QACR,OAAO,UAAU,WAAW;IAC9B;IAEA,IAAI,CAAC,WAAW,WAAW,GAAG,CAAA,GAAA,eAAO,EAAE;IACvC,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE;YAA6E;eAAvE,UAAU,UAAU,CAAC,IAAI,KAAK,KAAM,UAAU,UAAU,CAAC,IAAI,KAAK,KAAK,EAAA,gCAAA,UAAU,UAAU,CAAC,OAAO,CAAC,UAAU,UAAU,CAAC,WAAW,iBAA7D,oDAAA,8BAAmE,IAAI,MAAK;OAAW;QAAC,UAAU,UAAU;KAAC;IAEhN,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,SAAS;QACZ,GAAG,YAAY;uBACf;QACA,MAAK,gBAAsC,IAAI;YAC7C,yCAAyC;YACzC,IAAI,CAAC,SAAS;gBACZ,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,CAAC,SAAS;gBACZ,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF","sources":["packages/@react-stately/select/src/useSelectState.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 {CollectionStateBase, FocusStrategy} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';\nimport {SelectProps} from '@react-types/select';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {useMemo, useState} from 'react';\n\nexport interface SelectStateOptions<T> extends Omit<SelectProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T> extends SingleSelectListState<T>, OverlayTriggerState, FormValidationState {\n /** Whether the select is currently focused. */\n readonly isFocused: boolean,\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void,\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null,\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void,\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T extends object>(props: SelectStateOptions<T>): SelectState<T> {\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let listState = useSingleSelectListState({\n ...props,\n onSelectionChange: (key) => {\n if (props.onSelectionChange != null) {\n props.onSelectionChange(key);\n }\n\n triggerState.close();\n validationState.commitValidation();\n }\n });\n\n let validationState = useFormValidationState({\n ...props,\n value: listState.selectedKey\n });\n\n let [isFocused, setFocused] = useState(false);\n let isEmpty = useMemo(() => listState.collection.size === 0 || (listState.collection.size === 1 && listState.collection.getItem(listState.collection.getFirstKey()!)?.type === 'loader'), [listState.collection]);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (!isEmpty) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (!isEmpty) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n"],"names":[],"version":3,"file":"useSelectState.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/select",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.13",
|
|
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/form": "^3.1.
|
|
26
|
-
"@react-stately/list": "^3.12.
|
|
27
|
-
"@react-stately/overlays": "^3.6.
|
|
28
|
-
"@react-types/select": "^3.9.
|
|
29
|
-
"@react-types/shared": "^3.29.
|
|
25
|
+
"@react-stately/form": "^3.1.4",
|
|
26
|
+
"@react-stately/list": "^3.12.2",
|
|
27
|
+
"@react-stately/overlays": "^3.6.16",
|
|
28
|
+
"@react-types/select": "^3.9.12",
|
|
29
|
+
"@react-types/shared": "^3.29.1",
|
|
30
30
|
"@swc/helpers": "^0.5.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "9c77d4e8267ed39469c65f65da94ece7be509874"
|
|
39
39
|
}
|
package/src/useSelectState.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {FormValidationState, useFormValidationState} from '@react-stately/form';
|
|
|
15
15
|
import {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';
|
|
16
16
|
import {SelectProps} from '@react-types/select';
|
|
17
17
|
import {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';
|
|
18
|
-
import {useState} from 'react';
|
|
18
|
+
import {useMemo, useState} from 'react';
|
|
19
19
|
|
|
20
20
|
export interface SelectStateOptions<T> extends Omit<SelectProps<T>, 'children'>, CollectionStateBase<T> {}
|
|
21
21
|
|
|
@@ -62,6 +62,7 @@ export function useSelectState<T extends object>(props: SelectStateOptions<T>):
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
let [isFocused, setFocused] = useState(false);
|
|
65
|
+
let isEmpty = useMemo(() => listState.collection.size === 0 || (listState.collection.size === 1 && listState.collection.getItem(listState.collection.getFirstKey()!)?.type === 'loader'), [listState.collection]);
|
|
65
66
|
|
|
66
67
|
return {
|
|
67
68
|
...validationState,
|
|
@@ -70,13 +71,13 @@ export function useSelectState<T extends object>(props: SelectStateOptions<T>):
|
|
|
70
71
|
focusStrategy,
|
|
71
72
|
open(focusStrategy: FocusStrategy | null = null) {
|
|
72
73
|
// Don't open if the collection is empty.
|
|
73
|
-
if (
|
|
74
|
+
if (!isEmpty) {
|
|
74
75
|
setFocusStrategy(focusStrategy);
|
|
75
76
|
triggerState.open();
|
|
76
77
|
}
|
|
77
78
|
},
|
|
78
79
|
toggle(focusStrategy: FocusStrategy | null = null) {
|
|
79
|
-
if (
|
|
80
|
+
if (!isEmpty) {
|
|
80
81
|
setFocusStrategy(focusStrategy);
|
|
81
82
|
triggerState.toggle();
|
|
82
83
|
}
|