@react-stately/select 3.6.13 → 3.7.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/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CollectionStateBase, FocusStrategy } from "@react-types/shared";
1
+ import { CollectionStateBase, FocusStrategy, Key } from "@react-types/shared";
2
2
  import { FormValidationState } from "@react-stately/form";
3
3
  import { OverlayTriggerState } from "@react-stately/overlays";
4
4
  import { SelectProps } from "@react-types/select";
@@ -6,6 +6,8 @@ import { SingleSelectListState } from "@react-stately/list";
6
6
  export interface SelectStateOptions<T> extends Omit<SelectProps<T>, 'children'>, CollectionStateBase<T> {
7
7
  }
8
8
  export interface SelectState<T> extends SingleSelectListState<T>, OverlayTriggerState, FormValidationState {
9
+ /** The default selected key. */
10
+ readonly defaultSelectedKey: Key | null;
9
11
  /** Whether the select is currently focused. */
10
12
  readonly isFocused: boolean;
11
13
  /** Sets whether the select is focused. */
@@ -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,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"}
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,gCAAgC;IAChC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,GAAG,IAAI,CAAC;IAExC,+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,CA6C7F;AC7ED,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,26 +39,23 @@ 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
+ let [initialSelectedKey] = (0, $5KJtg$react.useState)(listState.selectedKey);
43
+ var _props_defaultSelectedKey;
48
44
  return {
49
45
  ...validationState,
50
46
  ...listState,
51
47
  ...triggerState,
48
+ defaultSelectedKey: (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : initialSelectedKey,
52
49
  focusStrategy: focusStrategy,
53
50
  open (focusStrategy = null) {
54
51
  // Don't open if the collection is empty.
55
- if (!isEmpty) {
52
+ if (listState.collection.size !== 0) {
56
53
  setFocusStrategy(focusStrategy);
57
54
  triggerState.open();
58
55
  }
59
56
  },
60
57
  toggle (focusStrategy = null) {
61
- if (!isEmpty) {
58
+ if (listState.collection.size !== 0) {
62
59
  setFocusStrategy(focusStrategy);
63
60
  triggerState.toggle();
64
61
  }
@@ -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;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"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAoCM,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,CAAC,mBAAmB,GAAG,CAAA,GAAA,qBAAO,EAAE,UAAU,WAAW;QAMnC;IAJtB,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,SAAS;QACZ,GAAG,YAAY;QACf,oBAAoB,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B;uBAChD;QACA,MAAK,gBAAsC,IAAI;YAC7C,yCAAyC;YACzC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,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, Key} 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 /** The default selected key. */\n readonly defaultSelectedKey: Key | null,\n\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 [initialSelectedKey] = useState(listState.selectedKey);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n defaultSelectedKey: props.defaultSelectedKey ?? initialSelectedKey,\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = 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 = 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":"useSelectState.main.js.map"}
@@ -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, useMemo as $6FfNf$useMemo} from "react";
4
+ import {useState as $6FfNf$useState} from "react";
5
5
 
6
6
  /*
7
7
  * Copyright 2020 Adobe. All rights reserved.
@@ -33,26 +33,23 @@ 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
+ let [initialSelectedKey] = (0, $6FfNf$useState)(listState.selectedKey);
37
+ var _props_defaultSelectedKey;
42
38
  return {
43
39
  ...validationState,
44
40
  ...listState,
45
41
  ...triggerState,
42
+ defaultSelectedKey: (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : initialSelectedKey,
46
43
  focusStrategy: focusStrategy,
47
44
  open (focusStrategy = null) {
48
45
  // Don't open if the collection is empty.
49
- if (!isEmpty) {
46
+ if (listState.collection.size !== 0) {
50
47
  setFocusStrategy(focusStrategy);
51
48
  triggerState.open();
52
49
  }
53
50
  },
54
51
  toggle (focusStrategy = null) {
55
- if (!isEmpty) {
52
+ if (listState.collection.size !== 0) {
56
53
  setFocusStrategy(focusStrategy);
57
54
  triggerState.toggle();
58
55
  }
@@ -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, useMemo as $6FfNf$useMemo} from "react";
4
+ import {useState as $6FfNf$useState} from "react";
5
5
 
6
6
  /*
7
7
  * Copyright 2020 Adobe. All rights reserved.
@@ -33,26 +33,23 @@ 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
+ let [initialSelectedKey] = (0, $6FfNf$useState)(listState.selectedKey);
37
+ var _props_defaultSelectedKey;
42
38
  return {
43
39
  ...validationState,
44
40
  ...listState,
45
41
  ...triggerState,
42
+ defaultSelectedKey: (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : initialSelectedKey,
46
43
  focusStrategy: focusStrategy,
47
44
  open (focusStrategy = null) {
48
45
  // Don't open if the collection is empty.
49
- if (!isEmpty) {
46
+ if (listState.collection.size !== 0) {
50
47
  setFocusStrategy(focusStrategy);
51
48
  triggerState.open();
52
49
  }
53
50
  },
54
51
  toggle (focusStrategy = null) {
55
- if (!isEmpty) {
52
+ if (listState.collection.size !== 0) {
56
53
  setFocusStrategy(focusStrategy);
57
54
  triggerState.toggle();
58
55
  }
@@ -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;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"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAoCM,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,CAAC,mBAAmB,GAAG,CAAA,GAAA,eAAO,EAAE,UAAU,WAAW;QAMnC;IAJtB,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,SAAS;QACZ,GAAG,YAAY;QACf,oBAAoB,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B;uBAChD;QACA,MAAK,gBAAsC,IAAI;YAC7C,yCAAyC;YACzC,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,iBAAiB;gBACjB,aAAa,IAAI;YACnB;QACF;QACA,QAAO,gBAAsC,IAAI;YAC/C,IAAI,UAAU,UAAU,CAAC,IAAI,KAAK,GAAG;gBACnC,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, Key} 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 /** The default selected key. */\n readonly defaultSelectedKey: Key | null,\n\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 [initialSelectedKey] = useState(listState.selectedKey);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n defaultSelectedKey: props.defaultSelectedKey ?? initialSelectedKey,\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = 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 = 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":"useSelectState.module.js.map"}
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@react-stately/select",
3
- "version": "3.6.13",
3
+ "version": "3.7.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "types": "./dist/types.d.ts",
9
+ "source": "./src/index.ts",
10
+ "types": [
11
+ "./dist/types.d.ts",
12
+ "./src/index.ts"
13
+ ],
10
14
  "import": "./dist/import.mjs",
11
15
  "require": "./dist/main.js"
12
16
  },
@@ -22,11 +26,11 @@
22
26
  "url": "https://github.com/adobe/react-spectrum"
23
27
  },
24
28
  "dependencies": {
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",
29
+ "@react-stately/form": "^3.2.0",
30
+ "@react-stately/list": "^3.12.4",
31
+ "@react-stately/overlays": "^3.6.18",
32
+ "@react-types/select": "^3.10.0",
33
+ "@react-types/shared": "^3.31.0",
30
34
  "@swc/helpers": "^0.5.0"
31
35
  },
32
36
  "peerDependencies": {
@@ -35,5 +39,5 @@
35
39
  "publishConfig": {
36
40
  "access": "public"
37
41
  },
38
- "gitHead": "9c77d4e8267ed39469c65f65da94ece7be509874"
42
+ "gitHead": "8b9348ff255e018b2dd9b27e2a45507cadfa1d35"
39
43
  }
@@ -10,16 +10,19 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {CollectionStateBase, FocusStrategy} from '@react-types/shared';
13
+ import {CollectionStateBase, FocusStrategy, Key} from '@react-types/shared';
14
14
  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 {useMemo, useState} from 'react';
18
+ import {useState} from 'react';
19
19
 
20
20
  export interface SelectStateOptions<T> extends Omit<SelectProps<T>, 'children'>, CollectionStateBase<T> {}
21
21
 
22
22
  export interface SelectState<T> extends SingleSelectListState<T>, OverlayTriggerState, FormValidationState {
23
+ /** The default selected key. */
24
+ readonly defaultSelectedKey: Key | null,
25
+
23
26
  /** Whether the select is currently focused. */
24
27
  readonly isFocused: boolean,
25
28
 
@@ -62,22 +65,23 @@ export function useSelectState<T extends object>(props: SelectStateOptions<T>):
62
65
  });
63
66
 
64
67
  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]);
68
+ let [initialSelectedKey] = useState(listState.selectedKey);
66
69
 
67
70
  return {
68
71
  ...validationState,
69
72
  ...listState,
70
73
  ...triggerState,
74
+ defaultSelectedKey: props.defaultSelectedKey ?? initialSelectedKey,
71
75
  focusStrategy,
72
76
  open(focusStrategy: FocusStrategy | null = null) {
73
77
  // Don't open if the collection is empty.
74
- if (!isEmpty) {
78
+ if (listState.collection.size !== 0) {
75
79
  setFocusStrategy(focusStrategy);
76
80
  triggerState.open();
77
81
  }
78
82
  },
79
83
  toggle(focusStrategy: FocusStrategy | null = null) {
80
- if (!isEmpty) {
84
+ if (listState.collection.size !== 0) {
81
85
  setFocusStrategy(focusStrategy);
82
86
  triggerState.toggle();
83
87
  }