@react-stately/select 3.6.1-nightly.4324 → 3.6.1
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 +14 -6
- package/dist/main.js +14 -6
- package/dist/main.js.map +1 -1
- package/dist/module.js +14 -6
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +9 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/useSelectState.ts +21 -8
package/dist/import.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useFormValidationState as $e17gp$useFormValidationState} from "@react-stately/form";
|
|
2
|
-
import {
|
|
2
|
+
import {useOverlayTriggerState as $e17gp$useOverlayTriggerState} from "@react-stately/overlays";
|
|
3
3
|
import {useSingleSelectListState as $e17gp$useSingleSelectListState} from "@react-stately/list";
|
|
4
4
|
import {useState as $e17gp$useState} from "react";
|
|
5
5
|
|
|
@@ -28,7 +28,8 @@ import {useState as $e17gp$useState} from "react";
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
31
|
-
let triggerState = (0, $e17gp$
|
|
31
|
+
let triggerState = (0, $e17gp$useOverlayTriggerState)(props);
|
|
32
|
+
let [focusStrategy, setFocusStrategy] = (0, $e17gp$useState)(null);
|
|
32
33
|
let listState = (0, $e17gp$useSingleSelectListState)({
|
|
33
34
|
...props,
|
|
34
35
|
onSelectionChange: (key)=>{
|
|
@@ -46,12 +47,19 @@ function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
|
46
47
|
...validationState,
|
|
47
48
|
...listState,
|
|
48
49
|
...triggerState,
|
|
49
|
-
|
|
50
|
+
focusStrategy: focusStrategy,
|
|
51
|
+
open (focusStrategy = null) {
|
|
50
52
|
// Don't open if the collection is empty.
|
|
51
|
-
if (listState.collection.size !== 0)
|
|
53
|
+
if (listState.collection.size !== 0) {
|
|
54
|
+
setFocusStrategy(focusStrategy);
|
|
55
|
+
triggerState.open();
|
|
56
|
+
}
|
|
52
57
|
},
|
|
53
|
-
toggle (focusStrategy) {
|
|
54
|
-
if (listState.collection.size !== 0)
|
|
58
|
+
toggle (focusStrategy = null) {
|
|
59
|
+
if (listState.collection.size !== 0) {
|
|
60
|
+
setFocusStrategy(focusStrategy);
|
|
61
|
+
triggerState.toggle();
|
|
62
|
+
}
|
|
55
63
|
},
|
|
56
64
|
isFocused: isFocused,
|
|
57
65
|
setFocused: setFocused
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var $aJE2N$reactstatelyform = require("@react-stately/form");
|
|
2
|
-
var $aJE2N$
|
|
2
|
+
var $aJE2N$reactstatelyoverlays = require("@react-stately/overlays");
|
|
3
3
|
var $aJE2N$reactstatelylist = require("@react-stately/list");
|
|
4
4
|
var $aJE2N$react = require("react");
|
|
5
5
|
|
|
@@ -34,7 +34,8 @@ $parcel$export(module.exports, "useSelectState", () => $80ebb60e77198879$export$
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
function $80ebb60e77198879$export$5159ec8b34d4ec12(props) {
|
|
37
|
-
let triggerState = (0, $aJE2N$
|
|
37
|
+
let triggerState = (0, $aJE2N$reactstatelyoverlays.useOverlayTriggerState)(props);
|
|
38
|
+
let [focusStrategy, setFocusStrategy] = (0, $aJE2N$react.useState)(null);
|
|
38
39
|
let listState = (0, $aJE2N$reactstatelylist.useSingleSelectListState)({
|
|
39
40
|
...props,
|
|
40
41
|
onSelectionChange: (key)=>{
|
|
@@ -52,12 +53,19 @@ function $80ebb60e77198879$export$5159ec8b34d4ec12(props) {
|
|
|
52
53
|
...validationState,
|
|
53
54
|
...listState,
|
|
54
55
|
...triggerState,
|
|
55
|
-
|
|
56
|
+
focusStrategy: focusStrategy,
|
|
57
|
+
open (focusStrategy = null) {
|
|
56
58
|
// Don't open if the collection is empty.
|
|
57
|
-
if (listState.collection.size !== 0)
|
|
59
|
+
if (listState.collection.size !== 0) {
|
|
60
|
+
setFocusStrategy(focusStrategy);
|
|
61
|
+
triggerState.open();
|
|
62
|
+
}
|
|
58
63
|
},
|
|
59
|
-
toggle (focusStrategy) {
|
|
60
|
-
if (listState.collection.size !== 0)
|
|
64
|
+
toggle (focusStrategy = null) {
|
|
65
|
+
if (listState.collection.size !== 0) {
|
|
66
|
+
setFocusStrategy(focusStrategy);
|
|
67
|
+
triggerState.toggle();
|
|
68
|
+
}
|
|
61
69
|
},
|
|
62
70
|
isFocused: isFocused,
|
|
63
71
|
setFocused: setFocused
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAiC,KAA4B;IAC3E,IAAI,eAAe,CAAA,GAAA,kDAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAChE,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;IAEvC,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,SAAS;QACZ,GAAG,YAAY;uBACf;QACA,MAAK,gBAA+B,IAAI;YACtC,yCAAyC;YACzC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAA+B,IAAI;YACxC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF;;CD5EC","sources":["packages/@react-stately/select/src/index.ts","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\nexport {useSelectState} from './useSelectState';\n\nexport type {SelectProps} from '@react-types/select';\nexport type {SelectState, SelectStateOptions} from './useSelectState';\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, 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 {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,\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);\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\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n focusStrategy,\n open(focusStrategy: FocusStrategy = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy = null) {\n if (listState.collection.size !== 0) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useFormValidationState as $e17gp$useFormValidationState} from "@react-stately/form";
|
|
2
|
-
import {
|
|
2
|
+
import {useOverlayTriggerState as $e17gp$useOverlayTriggerState} from "@react-stately/overlays";
|
|
3
3
|
import {useSingleSelectListState as $e17gp$useSingleSelectListState} from "@react-stately/list";
|
|
4
4
|
import {useState as $e17gp$useState} from "react";
|
|
5
5
|
|
|
@@ -28,7 +28,8 @@ import {useState as $e17gp$useState} from "react";
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
31
|
-
let triggerState = (0, $e17gp$
|
|
31
|
+
let triggerState = (0, $e17gp$useOverlayTriggerState)(props);
|
|
32
|
+
let [focusStrategy, setFocusStrategy] = (0, $e17gp$useState)(null);
|
|
32
33
|
let listState = (0, $e17gp$useSingleSelectListState)({
|
|
33
34
|
...props,
|
|
34
35
|
onSelectionChange: (key)=>{
|
|
@@ -46,12 +47,19 @@ function $2bc3a590c5373a4e$export$5159ec8b34d4ec12(props) {
|
|
|
46
47
|
...validationState,
|
|
47
48
|
...listState,
|
|
48
49
|
...triggerState,
|
|
49
|
-
|
|
50
|
+
focusStrategy: focusStrategy,
|
|
51
|
+
open (focusStrategy = null) {
|
|
50
52
|
// Don't open if the collection is empty.
|
|
51
|
-
if (listState.collection.size !== 0)
|
|
53
|
+
if (listState.collection.size !== 0) {
|
|
54
|
+
setFocusStrategy(focusStrategy);
|
|
55
|
+
triggerState.open();
|
|
56
|
+
}
|
|
52
57
|
},
|
|
53
|
-
toggle (focusStrategy) {
|
|
54
|
-
if (listState.collection.size !== 0)
|
|
58
|
+
toggle (focusStrategy = null) {
|
|
59
|
+
if (listState.collection.size !== 0) {
|
|
60
|
+
setFocusStrategy(focusStrategy);
|
|
61
|
+
triggerState.toggle();
|
|
62
|
+
}
|
|
55
63
|
},
|
|
56
64
|
isFocused: isFocused,
|
|
57
65
|
setFocused: setFocused
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAiC,KAA4B;IAC3E,IAAI,eAAe,CAAA,GAAA,6BAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAChE,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;IAEvC,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,SAAS;QACZ,GAAG,YAAY;uBACf;QACA,MAAK,gBAA+B,IAAI;YACtC,yCAAyC;YACzC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAA+B,IAAI;YACxC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,iBAAiB;gBACjB,aAAa,MAAM;YACrB;QACF;mBACA;oBACA;IACF;AACF;;CD5EC","sources":["packages/@react-stately/select/src/index.ts","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\nexport {useSelectState} from './useSelectState';\n\nexport type {SelectProps} from '@react-types/select';\nexport type {SelectState, SelectStateOptions} from './useSelectState';\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, 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 {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,\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);\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\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n focusStrategy,\n open(focusStrategy: FocusStrategy = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy = null) {\n if (listState.collection.size !== 0) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { CollectionStateBase } from "@react-types/shared";
|
|
1
|
+
import { CollectionStateBase, FocusStrategy } from "@react-types/shared";
|
|
2
2
|
import { FormValidationState } from "@react-stately/form";
|
|
3
|
-
import {
|
|
3
|
+
import { OverlayTriggerState } from "@react-stately/overlays";
|
|
4
4
|
import { SelectProps } from "@react-types/select";
|
|
5
5
|
import { SingleSelectListState } from "@react-stately/list";
|
|
6
6
|
export interface SelectStateOptions<T> extends Omit<SelectProps<T>, 'children'>, CollectionStateBase<T> {
|
|
7
7
|
}
|
|
8
|
-
export interface SelectState<T> extends SingleSelectListState<T>,
|
|
8
|
+
export interface SelectState<T> extends SingleSelectListState<T>, OverlayTriggerState, FormValidationState {
|
|
9
9
|
/** Whether the select is currently focused. */
|
|
10
10
|
readonly isFocused: boolean;
|
|
11
11
|
/** Sets whether the select is focused. */
|
|
12
12
|
setFocused(isFocused: boolean): void;
|
|
13
|
+
/** Controls which item will be auto focused when the menu opens. */
|
|
14
|
+
readonly focusStrategy: FocusStrategy;
|
|
15
|
+
/** Opens the menu. */
|
|
16
|
+
open(focusStrategy?: FocusStrategy | null): void;
|
|
17
|
+
/** Toggles the menu. */
|
|
18
|
+
toggle(focusStrategy?: FocusStrategy | null): void;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* Provides state management for a select component. Handles building a collection
|
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,
|
|
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,CAAC;IAEtC,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,CA2C7F;ACxED,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/select",
|
|
3
|
-
"version": "3.6.1
|
|
3
|
+
"version": "3.6.1",
|
|
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.0.
|
|
26
|
-
"@react-stately/list": "3.10.2
|
|
27
|
-
"@react-stately/
|
|
28
|
-
"@react-types/select": "3.9.1
|
|
29
|
-
"@react-types/shared": "3.
|
|
25
|
+
"@react-stately/form": "^3.0.0",
|
|
26
|
+
"@react-stately/list": "^3.10.2",
|
|
27
|
+
"@react-stately/overlays": "^3.6.4",
|
|
28
|
+
"@react-types/select": "^3.9.1",
|
|
29
|
+
"@react-types/shared": "^3.22.0",
|
|
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": "86b38c87868ce7f262e0df905e5ac4eb2653791d"
|
|
39
39
|
}
|
package/src/useSelectState.ts
CHANGED
|
@@ -10,21 +10,30 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {CollectionStateBase} from '@react-types/shared';
|
|
13
|
+
import {CollectionStateBase, FocusStrategy} from '@react-types/shared';
|
|
14
14
|
import {FormValidationState, useFormValidationState} from '@react-stately/form';
|
|
15
|
-
import {
|
|
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
18
|
import {useState} from 'react';
|
|
19
19
|
|
|
20
20
|
export interface SelectStateOptions<T> extends Omit<SelectProps<T>, 'children'>, CollectionStateBase<T> {}
|
|
21
21
|
|
|
22
|
-
export interface SelectState<T> extends SingleSelectListState<T>,
|
|
22
|
+
export interface SelectState<T> extends SingleSelectListState<T>, OverlayTriggerState, FormValidationState {
|
|
23
23
|
/** Whether the select is currently focused. */
|
|
24
24
|
readonly isFocused: boolean,
|
|
25
25
|
|
|
26
26
|
/** Sets whether the select is focused. */
|
|
27
|
-
setFocused(isFocused: boolean): void
|
|
27
|
+
setFocused(isFocused: boolean): void,
|
|
28
|
+
|
|
29
|
+
/** Controls which item will be auto focused when the menu opens. */
|
|
30
|
+
readonly focusStrategy: FocusStrategy,
|
|
31
|
+
|
|
32
|
+
/** Opens the menu. */
|
|
33
|
+
open(focusStrategy?: FocusStrategy | null): void,
|
|
34
|
+
|
|
35
|
+
/** Toggles the menu. */
|
|
36
|
+
toggle(focusStrategy?: FocusStrategy | null): void
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
/**
|
|
@@ -33,7 +42,8 @@ export interface SelectState<T> extends SingleSelectListState<T>, MenuTriggerSta
|
|
|
33
42
|
* multiple selection state.
|
|
34
43
|
*/
|
|
35
44
|
export function useSelectState<T extends object>(props: SelectStateOptions<T>): SelectState<T> {
|
|
36
|
-
let triggerState =
|
|
45
|
+
let triggerState = useOverlayTriggerState(props);
|
|
46
|
+
let [focusStrategy, setFocusStrategy] = useState<FocusStrategy>(null);
|
|
37
47
|
let listState = useSingleSelectListState({
|
|
38
48
|
...props,
|
|
39
49
|
onSelectionChange: (key) => {
|
|
@@ -57,15 +67,18 @@ export function useSelectState<T extends object>(props: SelectStateOptions<T>):
|
|
|
57
67
|
...validationState,
|
|
58
68
|
...listState,
|
|
59
69
|
...triggerState,
|
|
60
|
-
|
|
70
|
+
focusStrategy,
|
|
71
|
+
open(focusStrategy: FocusStrategy = null) {
|
|
61
72
|
// Don't open if the collection is empty.
|
|
62
73
|
if (listState.collection.size !== 0) {
|
|
74
|
+
setFocusStrategy(focusStrategy);
|
|
63
75
|
triggerState.open();
|
|
64
76
|
}
|
|
65
77
|
},
|
|
66
|
-
toggle(focusStrategy) {
|
|
78
|
+
toggle(focusStrategy: FocusStrategy = null) {
|
|
67
79
|
if (listState.collection.size !== 0) {
|
|
68
|
-
|
|
80
|
+
setFocusStrategy(focusStrategy);
|
|
81
|
+
triggerState.toggle();
|
|
69
82
|
}
|
|
70
83
|
},
|
|
71
84
|
isFocused,
|