@vygruppen/spor-react 2.4.1 → 2.4.3
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/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +12 -0
- package/dist/{CountryCodeSelect-MNHFBDDO.mjs → CountryCodeSelect-GFQIGSFV.mjs} +1 -1
- package/dist/{chunk-FLORQZEA.mjs → chunk-Z3I6W6PC.mjs} +24 -8
- package/dist/index.d.ts +35 -6
- package/dist/index.js +23 -7
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/input/Autosuggest.tsx +58 -9
- package/src/input/Combobox.tsx +9 -3
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> @vygruppen/spor-react@2.4.
|
2
|
+
> @vygruppen/spor-react@2.4.3 build
|
3
3
|
> tsup src/index.tsx --dts --treeshake --format cjs,esm
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: src/index.tsx
|
@@ -10,12 +10,12 @@
|
|
10
10
|
[34mESM[39m Build start
|
11
11
|
[34mDTS[39m Build start
|
12
12
|
"toTime" is imported from external module "@internationalized/date" but never used in "dist/index.js".
|
13
|
-
"toTime" is imported from external module "@internationalized/date" but never used in "dist/chunk-
|
14
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
15
|
-
[32mCJS[39m ⚡️ Build success in
|
13
|
+
"toTime" is imported from external module "@internationalized/date" but never used in "dist/chunk-Z3I6W6PC.mjs".
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m896.27 KB[39m
|
15
|
+
[32mCJS[39m ⚡️ Build success in 5484ms
|
16
16
|
[32mESM[39m [1mdist/index.mjs [22m[32m2.08 KB[39m
|
17
|
-
[32mESM[39m [1mdist/CountryCodeSelect-
|
18
|
-
[32mESM[39m [1mdist/chunk-
|
19
|
-
[32mESM[39m ⚡️ Build success in
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
21
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
17
|
+
[32mESM[39m [1mdist/CountryCodeSelect-GFQIGSFV.mjs [22m[32m351.67 KB[39m
|
18
|
+
[32mESM[39m [1mdist/chunk-Z3I6W6PC.mjs [22m[32m416.47 KB[39m
|
19
|
+
[32mESM[39m ⚡️ Build success in 5484ms
|
20
|
+
[32mDTS[39m ⚡️ Build success in 22623ms
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m262.86 KB[39m
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @vygruppen/spor-react
|
2
2
|
|
3
|
+
## 2.4.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 5640417f: Autosuggest: Fix a bug where the onSelectionChanged was called with no item on nested lists
|
8
|
+
|
9
|
+
## 2.4.2
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- a5f843bc: Autosuggest: Return the entire item selected, not just the list
|
14
|
+
|
3
15
|
## 2.4.1
|
4
16
|
|
5
17
|
### Patch Changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-
|
1
|
+
import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-Z3I6W6PC.mjs';
|
2
2
|
import React from 'react';
|
3
3
|
|
4
4
|
// ../../node_modules/awesome-phonenumber/index-esm.mjs
|
@@ -4022,9 +4022,8 @@ var AttachedInputs = ({
|
|
4022
4022
|
function Autosuggest({
|
4023
4023
|
label,
|
4024
4024
|
fetcher,
|
4025
|
-
children,
|
4026
4025
|
onSelectionChange,
|
4027
|
-
...
|
4026
|
+
...props
|
4028
4027
|
}) {
|
4029
4028
|
const list2 = useAsyncList({
|
4030
4029
|
async load({ filterText }) {
|
@@ -4033,6 +4032,20 @@ function Autosuggest({
|
|
4033
4032
|
};
|
4034
4033
|
}
|
4035
4034
|
});
|
4035
|
+
const handleSelectionChange = (key) => {
|
4036
|
+
if (!onSelectionChange) {
|
4037
|
+
return;
|
4038
|
+
}
|
4039
|
+
let selectedItem = list2.getItem(key);
|
4040
|
+
if (!selectedItem) {
|
4041
|
+
selectedItem = list2.items.flatMap(
|
4042
|
+
(item) => "children" in item && Array.isArray(item.children) ? item.children : []
|
4043
|
+
).find((child) => child.key === key);
|
4044
|
+
}
|
4045
|
+
if (selectedItem) {
|
4046
|
+
onSelectionChange(selectedItem);
|
4047
|
+
}
|
4048
|
+
};
|
4036
4049
|
return /* @__PURE__ */ React49__default.createElement(
|
4037
4050
|
Combobox,
|
4038
4051
|
{
|
@@ -4040,11 +4053,10 @@ function Autosuggest({
|
|
4040
4053
|
items: list2.items,
|
4041
4054
|
inputValue: list2.filterText,
|
4042
4055
|
onInputChange: list2.setFilterText,
|
4056
|
+
onSelectionChange: handleSelectionChange,
|
4043
4057
|
isLoading: list2.isLoading,
|
4044
|
-
|
4045
|
-
|
4046
|
-
},
|
4047
|
-
children
|
4058
|
+
...props
|
4059
|
+
}
|
4048
4060
|
);
|
4049
4061
|
}
|
4050
4062
|
var Dialog = ({ title, children, ...props }) => {
|
@@ -4232,6 +4244,8 @@ function Combobox({
|
|
4232
4244
|
marginTop,
|
4233
4245
|
marginX,
|
4234
4246
|
marginY,
|
4247
|
+
marginRight,
|
4248
|
+
marginLeft,
|
4235
4249
|
paddingBottom,
|
4236
4250
|
paddingRight,
|
4237
4251
|
paddingTop,
|
@@ -4261,7 +4275,7 @@ function Combobox({
|
|
4261
4275
|
},
|
4262
4276
|
state2
|
4263
4277
|
);
|
4264
|
-
return /* @__PURE__ */ React49__default.createElement(
|
4278
|
+
return /* @__PURE__ */ React49__default.createElement(React49__default.Fragment, null, /* @__PURE__ */ React49__default.createElement(
|
4265
4279
|
Input,
|
4266
4280
|
{
|
4267
4281
|
...inputProps,
|
@@ -4274,6 +4288,8 @@ function Combobox({
|
|
4274
4288
|
borderTopRightRadius,
|
4275
4289
|
marginBottom,
|
4276
4290
|
marginTop,
|
4291
|
+
marginRight,
|
4292
|
+
marginLeft,
|
4277
4293
|
marginX,
|
4278
4294
|
marginY,
|
4279
4295
|
paddingBottom,
|
@@ -4923,7 +4939,7 @@ var texts13 = createTexts({
|
|
4923
4939
|
sv: "Telefonnummer"
|
4924
4940
|
}
|
4925
4941
|
});
|
4926
|
-
var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-
|
4942
|
+
var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-GFQIGSFV.mjs'));
|
4927
4943
|
var Radio = forwardRef((props, ref) => {
|
4928
4944
|
return /* @__PURE__ */ React49__default.createElement(Radio$1, { ...props, ref });
|
4929
4945
|
});
|
package/dist/index.d.ts
CHANGED
@@ -644,10 +644,17 @@ type AutosuggestProps<T> = {
|
|
644
644
|
* */
|
645
645
|
children: ComboboxProps<T>["children"];
|
646
646
|
/**
|
647
|
-
* Callback for when the selection changes.
|
647
|
+
* Callback for when the selection changes. Returns the entire item.
|
648
648
|
*/
|
649
|
-
onSelectionChange?:
|
650
|
-
|
649
|
+
onSelectionChange?: (item: T) => void;
|
650
|
+
/** The selected item key (controlled) */
|
651
|
+
selectedKey?: ComboboxProps<T>["selectedKey"];
|
652
|
+
/** What should open the menu.
|
653
|
+
*
|
654
|
+
* Defaults to "input"
|
655
|
+
*/
|
656
|
+
menuTrigger?: ComboboxProps<T>["menuTrigger"];
|
657
|
+
} & Pick<InputProps, "marginTop" | "marginBottom" | "marginRight" | "marginLeft" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
|
651
658
|
/**
|
652
659
|
* A component that provides an autocomplete search field with suggestions.
|
653
660
|
*
|
@@ -678,8 +685,30 @@ type AutosuggestProps<T> = {
|
|
678
685
|
* );
|
679
686
|
* };
|
680
687
|
* ```
|
688
|
+
*
|
689
|
+
* The `fetcher` function can be any function that returns an iterable of items. This means that you can use any API library you want, as long as it returns an iterable of items.
|
690
|
+
*
|
691
|
+
* The items need to have a `key` property, which is used to identify the item. The `key` property can be any type, but it needs to be unique for each item.
|
692
|
+
*
|
693
|
+
* ```tsx
|
694
|
+
* [{ key: 'some-key', ...}, { key: 'some-other-key', ... }]
|
695
|
+
* ```
|
696
|
+
*
|
697
|
+
* You can also return a set of nested items, which will be rendered as a sub-list (or section). This is useful if you want to group your items. These items need to have a title prop (for labelling the section), as well as a `children` prop, which in turn will contain an iterable of items:
|
698
|
+
*
|
699
|
+
* ```tsx
|
700
|
+
* [
|
701
|
+
* {
|
702
|
+
* title: 'The title of the section',
|
703
|
+
* children: [{ key: 'some-key', ... }]
|
704
|
+
* },
|
705
|
+
* {...}
|
706
|
+
* ]
|
707
|
+
* ```
|
708
|
+
*
|
709
|
+
* The `onSelectionChanged` will return the correct `item` (the one with the matching `key`), even if the item is in a sub-list.
|
681
710
|
*/
|
682
|
-
declare function Autosuggest<T extends object>({ label, fetcher,
|
711
|
+
declare function Autosuggest<T extends object>({ label, fetcher, onSelectionChange, ...props }: AutosuggestProps<T>): React__default.JSX.Element;
|
683
712
|
|
684
713
|
type CardSelectProps = BoxProps & {
|
685
714
|
/** The design of the trigger button.
|
@@ -816,7 +845,7 @@ type ComboboxProps<T> = AriaComboBoxProps<T> & {
|
|
816
845
|
label: string;
|
817
846
|
/** Whether or not the combobox is waiting for new suggestions */
|
818
847
|
isLoading?: boolean;
|
819
|
-
} & Pick<InputProps, "marginTop" | "marginBottom" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
|
848
|
+
} & Pick<InputProps, "marginTop" | "marginBottom" | "marginRight" | "marginLeft" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
|
820
849
|
/**
|
821
850
|
* A combobox is a combination of an input and a list of suggestions.
|
822
851
|
*
|
@@ -840,7 +869,7 @@ type ComboboxProps<T> = AriaComboBoxProps<T> & {
|
|
840
869
|
* </Combobox>
|
841
870
|
* ```
|
842
871
|
*/
|
843
|
-
declare function Combobox<T extends object>({ label, isLoading, leftIcon, rightIcon, borderBottomLeftRadius, borderBottomRightRadius, borderTopLeftRadius, borderTopRightRadius, marginBottom, marginTop, marginX, marginY, paddingBottom, paddingRight, paddingTop, paddingLeft, paddingX, paddingY, onFocus, ...rest }: ComboboxProps<T>): React__default.JSX.Element;
|
872
|
+
declare function Combobox<T extends object>({ label, isLoading, leftIcon, rightIcon, borderBottomLeftRadius, borderBottomRightRadius, borderTopLeftRadius, borderTopRightRadius, marginBottom, marginTop, marginX, marginY, marginRight, marginLeft, paddingBottom, paddingRight, paddingTop, paddingLeft, paddingX, paddingY, onFocus, ...rest }: ComboboxProps<T>): React__default.JSX.Element;
|
844
873
|
|
845
874
|
type FormControlProps = FormControlProps$1;
|
846
875
|
declare const FormControl: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", FormControlProps$1>;
|
package/dist/index.js
CHANGED
@@ -3753,9 +3753,8 @@ var init_AttachedInputs = __esm({
|
|
3753
3753
|
function Autosuggest({
|
3754
3754
|
label,
|
3755
3755
|
fetcher,
|
3756
|
-
children,
|
3757
3756
|
onSelectionChange,
|
3758
|
-
...
|
3757
|
+
...props
|
3759
3758
|
}) {
|
3760
3759
|
const list2 = reactStately.useAsyncList({
|
3761
3760
|
async load({ filterText }) {
|
@@ -3764,6 +3763,20 @@ function Autosuggest({
|
|
3764
3763
|
};
|
3765
3764
|
}
|
3766
3765
|
});
|
3766
|
+
const handleSelectionChange = (key) => {
|
3767
|
+
if (!onSelectionChange) {
|
3768
|
+
return;
|
3769
|
+
}
|
3770
|
+
let selectedItem = list2.getItem(key);
|
3771
|
+
if (!selectedItem) {
|
3772
|
+
selectedItem = list2.items.flatMap(
|
3773
|
+
(item) => "children" in item && Array.isArray(item.children) ? item.children : []
|
3774
|
+
).find((child) => child.key === key);
|
3775
|
+
}
|
3776
|
+
if (selectedItem) {
|
3777
|
+
onSelectionChange(selectedItem);
|
3778
|
+
}
|
3779
|
+
};
|
3767
3780
|
return /* @__PURE__ */ React49__namespace.default.createElement(
|
3768
3781
|
Combobox,
|
3769
3782
|
{
|
@@ -3771,11 +3784,10 @@ function Autosuggest({
|
|
3771
3784
|
items: list2.items,
|
3772
3785
|
inputValue: list2.filterText,
|
3773
3786
|
onInputChange: list2.setFilterText,
|
3787
|
+
onSelectionChange: handleSelectionChange,
|
3774
3788
|
isLoading: list2.isLoading,
|
3775
|
-
|
3776
|
-
|
3777
|
-
},
|
3778
|
-
children
|
3789
|
+
...props
|
3790
|
+
}
|
3779
3791
|
);
|
3780
3792
|
}
|
3781
3793
|
var init_Autosuggest = __esm({
|
@@ -4747,6 +4759,8 @@ function Combobox({
|
|
4747
4759
|
marginTop,
|
4748
4760
|
marginX,
|
4749
4761
|
marginY,
|
4762
|
+
marginRight,
|
4763
|
+
marginLeft,
|
4750
4764
|
paddingBottom,
|
4751
4765
|
paddingRight,
|
4752
4766
|
paddingTop,
|
@@ -4776,7 +4790,7 @@ function Combobox({
|
|
4776
4790
|
},
|
4777
4791
|
state2
|
4778
4792
|
);
|
4779
|
-
return /* @__PURE__ */ React49__namespace.default.createElement(
|
4793
|
+
return /* @__PURE__ */ React49__namespace.default.createElement(React49__namespace.default.Fragment, null, /* @__PURE__ */ React49__namespace.default.createElement(
|
4780
4794
|
exports.Input,
|
4781
4795
|
{
|
4782
4796
|
...inputProps,
|
@@ -4789,6 +4803,8 @@ function Combobox({
|
|
4789
4803
|
borderTopRightRadius,
|
4790
4804
|
marginBottom,
|
4791
4805
|
marginTop,
|
4806
|
+
marginRight,
|
4807
|
+
marginLeft,
|
4792
4808
|
marginX,
|
4793
4809
|
marginY,
|
4794
4810
|
paddingBottom,
|
package/dist/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Autosuggest, Badge, Box, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, NumericStepper, PasswordInput, PhoneNumberInput, PlayPauseButton, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, PopoverWizardBody, ProgressBar, ProgressLoader, Radio, RadioGroup, ScaleFade, SearchInput, Section, SelectItem, SelectItemDescription, SelectItemLabel, SimpleDrawer, SimpleGrid, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, Tr, TravelTag, VStack, VyLogo, WizardPopover, Wrap, WrapItem, createTexts, extendTheme, fontFaces, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, useTheme, useToast, useToken, useTranslation } from './chunk-
|
1
|
+
export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Autosuggest, Badge, Box, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, NumericStepper, PasswordInput, PhoneNumberInput, PlayPauseButton, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, PopoverWizardBody, ProgressBar, ProgressLoader, Radio, RadioGroup, ScaleFade, SearchInput, Section, SelectItem, SelectItemDescription, SelectItemLabel, SimpleDrawer, SimpleGrid, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, Tr, TravelTag, VStack, VyLogo, WizardPopover, Wrap, WrapItem, createTexts, extendTheme, fontFaces, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, useTheme, useToast, useToken, useTranslation } from './chunk-Z3I6W6PC.mjs';
|
package/package.json
CHANGED
@@ -39,13 +39,22 @@ type AutosuggestProps<T> = {
|
|
39
39
|
* */
|
40
40
|
children: ComboboxProps<T>["children"];
|
41
41
|
/**
|
42
|
-
* Callback for when the selection changes.
|
42
|
+
* Callback for when the selection changes. Returns the entire item.
|
43
43
|
*/
|
44
|
-
onSelectionChange?:
|
44
|
+
onSelectionChange?: (item: T) => void;
|
45
|
+
/** The selected item key (controlled) */
|
46
|
+
selectedKey?: ComboboxProps<T>["selectedKey"];
|
47
|
+
/** What should open the menu.
|
48
|
+
*
|
49
|
+
* Defaults to "input"
|
50
|
+
*/
|
51
|
+
menuTrigger?: ComboboxProps<T>["menuTrigger"];
|
45
52
|
} & Pick<
|
46
53
|
InputProps,
|
47
54
|
| "marginTop"
|
48
55
|
| "marginBottom"
|
56
|
+
| "marginRight"
|
57
|
+
| "marginLeft"
|
49
58
|
| "marginY"
|
50
59
|
| "marginX"
|
51
60
|
| "paddingTop"
|
@@ -92,13 +101,34 @@ type AutosuggestProps<T> = {
|
|
92
101
|
* );
|
93
102
|
* };
|
94
103
|
* ```
|
104
|
+
*
|
105
|
+
* The `fetcher` function can be any function that returns an iterable of items. This means that you can use any API library you want, as long as it returns an iterable of items.
|
106
|
+
*
|
107
|
+
* The items need to have a `key` property, which is used to identify the item. The `key` property can be any type, but it needs to be unique for each item.
|
108
|
+
*
|
109
|
+
* ```tsx
|
110
|
+
* [{ key: 'some-key', ...}, { key: 'some-other-key', ... }]
|
111
|
+
* ```
|
112
|
+
*
|
113
|
+
* You can also return a set of nested items, which will be rendered as a sub-list (or section). This is useful if you want to group your items. These items need to have a title prop (for labelling the section), as well as a `children` prop, which in turn will contain an iterable of items:
|
114
|
+
*
|
115
|
+
* ```tsx
|
116
|
+
* [
|
117
|
+
* {
|
118
|
+
* title: 'The title of the section',
|
119
|
+
* children: [{ key: 'some-key', ... }]
|
120
|
+
* },
|
121
|
+
* {...}
|
122
|
+
* ]
|
123
|
+
* ```
|
124
|
+
*
|
125
|
+
* The `onSelectionChanged` will return the correct `item` (the one with the matching `key`), even if the item is in a sub-list.
|
95
126
|
*/
|
96
127
|
export function Autosuggest<T extends object>({
|
97
128
|
label,
|
98
129
|
fetcher,
|
99
|
-
children,
|
100
130
|
onSelectionChange,
|
101
|
-
...
|
131
|
+
...props
|
102
132
|
}: AutosuggestProps<T>) {
|
103
133
|
const list = useAsyncList<T>({
|
104
134
|
async load({ filterText }) {
|
@@ -107,17 +137,36 @@ export function Autosuggest<T extends object>({
|
|
107
137
|
};
|
108
138
|
},
|
109
139
|
});
|
140
|
+
|
141
|
+
const handleSelectionChange = (key: React.Key) => {
|
142
|
+
if (!onSelectionChange) {
|
143
|
+
return;
|
144
|
+
}
|
145
|
+
|
146
|
+
let selectedItem = list.getItem(key);
|
147
|
+
if (!selectedItem) {
|
148
|
+
// If the item is not in the list, it might be in a sub-list
|
149
|
+
selectedItem = list.items
|
150
|
+
.flatMap((item) =>
|
151
|
+
"children" in item && Array.isArray(item.children)
|
152
|
+
? item.children
|
153
|
+
: []
|
154
|
+
)
|
155
|
+
.find((child) => child.key === key);
|
156
|
+
}
|
157
|
+
if (selectedItem) {
|
158
|
+
onSelectionChange(selectedItem);
|
159
|
+
}
|
160
|
+
};
|
110
161
|
return (
|
111
162
|
<Combobox
|
112
163
|
label={label}
|
113
164
|
items={list.items}
|
114
165
|
inputValue={list.filterText}
|
115
166
|
onInputChange={list.setFilterText}
|
167
|
+
onSelectionChange={handleSelectionChange}
|
116
168
|
isLoading={list.isLoading}
|
117
|
-
|
118
|
-
|
119
|
-
>
|
120
|
-
{children}
|
121
|
-
</Combobox>
|
169
|
+
{...props}
|
170
|
+
/>
|
122
171
|
);
|
123
172
|
}
|
package/src/input/Combobox.tsx
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import React, { useRef } from "react";
|
2
2
|
import { AriaComboBoxProps, useComboBox, useFilter } from "react-aria";
|
3
3
|
import { useComboBoxState } from "react-stately";
|
4
|
-
import { ColorSpinner,
|
4
|
+
import { ColorSpinner, Input, InputProps, ListBox } from "..";
|
5
5
|
import { Popover } from "./Popover";
|
6
6
|
|
7
7
|
export type ComboboxProps<T> = AriaComboBoxProps<T> & {
|
@@ -13,6 +13,8 @@ export type ComboboxProps<T> = AriaComboBoxProps<T> & {
|
|
13
13
|
InputProps,
|
14
14
|
| "marginTop"
|
15
15
|
| "marginBottom"
|
16
|
+
| "marginRight"
|
17
|
+
| "marginLeft"
|
16
18
|
| "marginY"
|
17
19
|
| "marginX"
|
18
20
|
| "paddingTop"
|
@@ -65,6 +67,8 @@ export function Combobox<T extends object>({
|
|
65
67
|
marginTop,
|
66
68
|
marginX,
|
67
69
|
marginY,
|
70
|
+
marginRight,
|
71
|
+
marginLeft,
|
68
72
|
paddingBottom,
|
69
73
|
paddingRight,
|
70
74
|
paddingTop,
|
@@ -98,7 +102,7 @@ export function Combobox<T extends object>({
|
|
98
102
|
);
|
99
103
|
|
100
104
|
return (
|
101
|
-
|
105
|
+
<>
|
102
106
|
<Input
|
103
107
|
{...inputProps}
|
104
108
|
ref={inputRef}
|
@@ -110,6 +114,8 @@ export function Combobox<T extends object>({
|
|
110
114
|
borderTopRightRadius={borderTopRightRadius}
|
111
115
|
marginBottom={marginBottom}
|
112
116
|
marginTop={marginTop}
|
117
|
+
marginRight={marginRight}
|
118
|
+
marginLeft={marginLeft}
|
113
119
|
marginX={marginX}
|
114
120
|
marginY={marginY}
|
115
121
|
paddingBottom={paddingBottom}
|
@@ -153,6 +159,6 @@ export function Combobox<T extends object>({
|
|
153
159
|
</ListBox>
|
154
160
|
</Popover>
|
155
161
|
)}
|
156
|
-
|
162
|
+
</>
|
157
163
|
);
|
158
164
|
}
|