@vygruppen/spor-react 2.5.0 → 2.5.2
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 +14 -0
- package/dist/{CountryCodeSelect-ZTEYBERS.mjs → CountryCodeSelect-KO3QKE4X.mjs} +1 -1
- package/dist/{chunk-7GRTZA6T.mjs → chunk-PFCQ55ZF.mjs} +36 -8
- package/dist/index.d.ts +3 -2
- package/dist/index.js +36 -7
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/datepicker/TimePicker.tsx +1 -1
- package/src/input/Combobox.tsx +39 -6
- package/src/input/ListBox.tsx +3 -0
- package/src/theme/components/datepicker.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> @vygruppen/spor-react@2.5.
|
2
|
+
> @vygruppen/spor-react@2.5.2 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-PFCQ55ZF.mjs".
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m896.29 KB[39m
|
15
|
+
[32mCJS[39m ⚡️ Build success in 6499ms
|
16
16
|
[32mESM[39m [1mdist/index.mjs [22m[32m2.06 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[32m259.
|
17
|
+
[32mESM[39m [1mdist/CountryCodeSelect-KO3QKE4X.mjs [22m[32m351.67 KB[39m
|
18
|
+
[32mESM[39m [1mdist/chunk-PFCQ55ZF.mjs [22m[32m416.47 KB[39m
|
19
|
+
[32mESM[39m ⚡️ Build success in 6500ms
|
20
|
+
[32mDTS[39m ⚡️ Build success in 24524ms
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m259.37 KB[39m
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @vygruppen/spor-react
|
2
2
|
|
3
|
+
## 2.5.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- a884fea5: Combobox: Make the width of the attached listbox never outgrow its input field
|
8
|
+
|
9
|
+
## 2.5.1
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 28a772f4: Datepicker, Timepicker: Changed color to meet contrast minimum requriement
|
14
|
+
- f49fa9d2: TimePicker: Fixes typing bug in onChange prop
|
15
|
+
- 643afb0d: Combobox: Fix glitchy loading state
|
16
|
+
|
3
17
|
## 2.5.0
|
4
18
|
|
5
19
|
### Minor Changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-
|
1
|
+
import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-PFCQ55ZF.mjs';
|
2
2
|
import React from 'react';
|
3
3
|
|
4
4
|
// ../../node_modules/awesome-phonenumber/index-esm.mjs
|
@@ -4219,10 +4219,12 @@ function Combobox({
|
|
4219
4219
|
const inputRef = useRef(null);
|
4220
4220
|
const listBoxRef = useRef(null);
|
4221
4221
|
const popoverRef = useRef(null);
|
4222
|
+
const inputWidth = useInputWidth(inputRef);
|
4222
4223
|
const state2 = useComboBoxState({
|
4223
4224
|
...rest,
|
4224
4225
|
defaultFilter: contains2,
|
4225
|
-
allowsEmptyCollection: Boolean(emptyContent)
|
4226
|
+
allowsEmptyCollection: Boolean(emptyContent),
|
4227
|
+
shouldCloseOnBlur: true
|
4226
4228
|
});
|
4227
4229
|
const {
|
4228
4230
|
inputProps: { size: size2, ...inputProps },
|
@@ -4242,8 +4244,8 @@ function Combobox({
|
|
4242
4244
|
...inputProps,
|
4243
4245
|
ref: inputRef,
|
4244
4246
|
label,
|
4245
|
-
borderBottomLeftRadius: state2.isOpen ? 0 : borderBottomLeftRadius,
|
4246
|
-
borderBottomRightRadius: state2.isOpen ? 0 : borderBottomRightRadius,
|
4247
|
+
borderBottomLeftRadius: state2.isOpen && !isLoading ? 0 : borderBottomLeftRadius,
|
4248
|
+
borderBottomRightRadius: state2.isOpen && !isLoading ? 0 : borderBottomRightRadius,
|
4247
4249
|
borderTopLeftRadius,
|
4248
4250
|
borderTopRightRadius,
|
4249
4251
|
marginBottom,
|
@@ -4273,7 +4275,7 @@ function Combobox({
|
|
4273
4275
|
}
|
4274
4276
|
) : rightIcon
|
4275
4277
|
}
|
4276
|
-
), state2.isOpen && /* @__PURE__ */ React49__default.createElement(
|
4278
|
+
), state2.isOpen && !isLoading && /* @__PURE__ */ React49__default.createElement(
|
4277
4279
|
Popover3,
|
4278
4280
|
{
|
4279
4281
|
state: state2,
|
@@ -4287,12 +4289,36 @@ function Combobox({
|
|
4287
4289
|
...listBoxProps,
|
4288
4290
|
state: state2,
|
4289
4291
|
listBoxRef,
|
4290
|
-
emptyContent
|
4292
|
+
emptyContent,
|
4293
|
+
maxWidth: inputWidth
|
4291
4294
|
},
|
4292
4295
|
rest.children
|
4293
4296
|
)
|
4294
4297
|
));
|
4295
4298
|
}
|
4299
|
+
var useInputWidth = (inputRef) => {
|
4300
|
+
const [inputWidth, setInputWidth] = useState("auto");
|
4301
|
+
useEffect(() => {
|
4302
|
+
const onResize = debounce(() => {
|
4303
|
+
if (inputRef.current) {
|
4304
|
+
setInputWidth(`${inputRef.current.offsetWidth}px`);
|
4305
|
+
}
|
4306
|
+
}, 67);
|
4307
|
+
window.addEventListener("resize", onResize);
|
4308
|
+
return () => window.removeEventListener("resize", onResize);
|
4309
|
+
}, []);
|
4310
|
+
return inputWidth;
|
4311
|
+
};
|
4312
|
+
var debounce = (fn, ms = 100) => {
|
4313
|
+
let timer;
|
4314
|
+
return () => {
|
4315
|
+
clearTimeout(timer);
|
4316
|
+
timer = setTimeout(() => {
|
4317
|
+
timer = null;
|
4318
|
+
fn();
|
4319
|
+
}, ms);
|
4320
|
+
};
|
4321
|
+
};
|
4296
4322
|
var FormControl = forwardRef((props, ref) => {
|
4297
4323
|
return /* @__PURE__ */ React49__default.createElement(FormControl$1, { ...props, ref });
|
4298
4324
|
});
|
@@ -4362,6 +4388,7 @@ function ListBox({
|
|
4362
4388
|
isLoading,
|
4363
4389
|
listBoxRef,
|
4364
4390
|
state: state2,
|
4391
|
+
maxWidth,
|
4365
4392
|
...props
|
4366
4393
|
}) {
|
4367
4394
|
const { listBoxProps } = useListBox(props, state2, listBoxRef);
|
@@ -4372,7 +4399,8 @@ function ListBox({
|
|
4372
4399
|
...listBoxProps,
|
4373
4400
|
ref: listBoxRef,
|
4374
4401
|
sx: styles2.container,
|
4375
|
-
"aria-busy": isLoading
|
4402
|
+
"aria-busy": isLoading,
|
4403
|
+
maxWidth
|
4376
4404
|
},
|
4377
4405
|
state2.collection.size === 0 && props.emptyContent,
|
4378
4406
|
Array.from(state2.collection).map(
|
@@ -4900,7 +4928,7 @@ var texts13 = createTexts({
|
|
4900
4928
|
sv: "Telefonnummer"
|
4901
4929
|
}
|
4902
4930
|
});
|
4903
|
-
var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-
|
4931
|
+
var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-KO3QKE4X.mjs'));
|
4904
4932
|
var Radio = forwardRef((props, ref) => {
|
4905
4933
|
return /* @__PURE__ */ React49__default.createElement(Radio$1, { ...props, ref });
|
4906
4934
|
});
|
@@ -11883,7 +11911,7 @@ var config13 = helpers6.defineMultiStyleConfig({
|
|
11883
11911
|
},
|
11884
11912
|
dateTimeSegment: {
|
11885
11913
|
color: mode(
|
11886
|
-
props.
|
11914
|
+
props.isEditable ? "darkGrey" : "dimGrey",
|
11887
11915
|
props.isPlaceholder ? "whiteAlpha.400" : "white"
|
11888
11916
|
)(props)
|
11889
11917
|
},
|
package/dist/index.d.ts
CHANGED
@@ -452,7 +452,7 @@ type DateRangePickerProps = AriaDateRangePickerProps<DateValue> & Pick<BoxProps,
|
|
452
452
|
*/
|
453
453
|
declare function DateRangePicker({ variant, minHeight, startName, endName, ...props }: DateRangePickerProps): React__default.JSX.Element;
|
454
454
|
|
455
|
-
type TimePickerProps = Omit<BoxProps, "defaultValue"> & {
|
455
|
+
type TimePickerProps = Omit<BoxProps, "defaultValue" | "onChange"> & {
|
456
456
|
/** The label. Defaults to a localized version of "Time" */
|
457
457
|
label?: string;
|
458
458
|
/** The name of the form field, if used in a regular form */
|
@@ -1013,6 +1013,7 @@ type ListBoxProps<T> = AriaListBoxProps<T> & Omit<BoxProps, "filter" | "autoFocu
|
|
1013
1013
|
state: ListState<T> | SelectState<T>;
|
1014
1014
|
/** UI to render if the collection is empty */
|
1015
1015
|
emptyContent?: React__default.ReactNode;
|
1016
|
+
maxWidth?: BoxProps["maxWidth"];
|
1016
1017
|
};
|
1017
1018
|
/**
|
1018
1019
|
* A component that renders a list box with selectable options.
|
@@ -1048,7 +1049,7 @@ type ListBoxProps<T> = AriaListBoxProps<T> & Omit<BoxProps, "filter" | "autoFocu
|
|
1048
1049
|
* );
|
1049
1050
|
* ```
|
1050
1051
|
*/
|
1051
|
-
declare function ListBox<T extends object>({ isLoading, listBoxRef, state, ...props }: ListBoxProps<T>): React__default.JSX.Element;
|
1052
|
+
declare function ListBox<T extends object>({ isLoading, listBoxRef, state, maxWidth, ...props }: ListBoxProps<T>): React__default.JSX.Element;
|
1052
1053
|
/**
|
1053
1054
|
* Renders a label for a listbox item.
|
1054
1055
|
*
|
package/dist/index.js
CHANGED
@@ -4729,10 +4729,12 @@ function Combobox({
|
|
4729
4729
|
const inputRef = React49.useRef(null);
|
4730
4730
|
const listBoxRef = React49.useRef(null);
|
4731
4731
|
const popoverRef = React49.useRef(null);
|
4732
|
+
const inputWidth = useInputWidth(inputRef);
|
4732
4733
|
const state2 = reactStately.useComboBoxState({
|
4733
4734
|
...rest,
|
4734
4735
|
defaultFilter: contains2,
|
4735
|
-
allowsEmptyCollection: Boolean(emptyContent)
|
4736
|
+
allowsEmptyCollection: Boolean(emptyContent),
|
4737
|
+
shouldCloseOnBlur: true
|
4736
4738
|
});
|
4737
4739
|
const {
|
4738
4740
|
inputProps: { size: size2, ...inputProps },
|
@@ -4752,8 +4754,8 @@ function Combobox({
|
|
4752
4754
|
...inputProps,
|
4753
4755
|
ref: inputRef,
|
4754
4756
|
label,
|
4755
|
-
borderBottomLeftRadius: state2.isOpen ? 0 : borderBottomLeftRadius,
|
4756
|
-
borderBottomRightRadius: state2.isOpen ? 0 : borderBottomRightRadius,
|
4757
|
+
borderBottomLeftRadius: state2.isOpen && !isLoading ? 0 : borderBottomLeftRadius,
|
4758
|
+
borderBottomRightRadius: state2.isOpen && !isLoading ? 0 : borderBottomRightRadius,
|
4757
4759
|
borderTopLeftRadius,
|
4758
4760
|
borderTopRightRadius,
|
4759
4761
|
marginBottom,
|
@@ -4783,7 +4785,7 @@ function Combobox({
|
|
4783
4785
|
}
|
4784
4786
|
) : rightIcon
|
4785
4787
|
}
|
4786
|
-
), state2.isOpen && /* @__PURE__ */ React49__namespace.default.createElement(
|
4788
|
+
), state2.isOpen && !isLoading && /* @__PURE__ */ React49__namespace.default.createElement(
|
4787
4789
|
Popover3,
|
4788
4790
|
{
|
4789
4791
|
state: state2,
|
@@ -4797,16 +4799,41 @@ function Combobox({
|
|
4797
4799
|
...listBoxProps,
|
4798
4800
|
state: state2,
|
4799
4801
|
listBoxRef,
|
4800
|
-
emptyContent
|
4802
|
+
emptyContent,
|
4803
|
+
maxWidth: inputWidth
|
4801
4804
|
},
|
4802
4805
|
rest.children
|
4803
4806
|
)
|
4804
4807
|
));
|
4805
4808
|
}
|
4809
|
+
var useInputWidth, debounce;
|
4806
4810
|
var init_Combobox = __esm({
|
4807
4811
|
"src/input/Combobox.tsx"() {
|
4808
4812
|
init_src();
|
4809
4813
|
init_Popover();
|
4814
|
+
useInputWidth = (inputRef) => {
|
4815
|
+
const [inputWidth, setInputWidth] = React49.useState("auto");
|
4816
|
+
React49.useEffect(() => {
|
4817
|
+
const onResize = debounce(() => {
|
4818
|
+
if (inputRef.current) {
|
4819
|
+
setInputWidth(`${inputRef.current.offsetWidth}px`);
|
4820
|
+
}
|
4821
|
+
}, 67);
|
4822
|
+
window.addEventListener("resize", onResize);
|
4823
|
+
return () => window.removeEventListener("resize", onResize);
|
4824
|
+
}, []);
|
4825
|
+
return inputWidth;
|
4826
|
+
};
|
4827
|
+
debounce = (fn, ms = 100) => {
|
4828
|
+
let timer;
|
4829
|
+
return () => {
|
4830
|
+
clearTimeout(timer);
|
4831
|
+
timer = setTimeout(() => {
|
4832
|
+
timer = null;
|
4833
|
+
fn();
|
4834
|
+
}, ms);
|
4835
|
+
};
|
4836
|
+
};
|
4810
4837
|
}
|
4811
4838
|
});
|
4812
4839
|
exports.FormControl = void 0;
|
@@ -4892,6 +4919,7 @@ function ListBox({
|
|
4892
4919
|
isLoading,
|
4893
4920
|
listBoxRef,
|
4894
4921
|
state: state2,
|
4922
|
+
maxWidth,
|
4895
4923
|
...props
|
4896
4924
|
}) {
|
4897
4925
|
const { listBoxProps } = reactAria.useListBox(props, state2, listBoxRef);
|
@@ -4902,7 +4930,8 @@ function ListBox({
|
|
4902
4930
|
...listBoxProps,
|
4903
4931
|
ref: listBoxRef,
|
4904
4932
|
sx: styles2.container,
|
4905
|
-
"aria-busy": isLoading
|
4933
|
+
"aria-busy": isLoading,
|
4934
|
+
maxWidth
|
4906
4935
|
},
|
4907
4936
|
state2.collection.size === 0 && props.emptyContent,
|
4908
4937
|
Array.from(state2.collection).map(
|
@@ -19954,7 +19983,7 @@ var init_datepicker2 = __esm({
|
|
19954
19983
|
},
|
19955
19984
|
dateTimeSegment: {
|
19956
19985
|
color: themeTools.mode(
|
19957
|
-
props.
|
19986
|
+
props.isEditable ? "darkGrey" : "dimGrey",
|
19958
19987
|
props.isPlaceholder ? "whiteAlpha.400" : "white"
|
19959
19988
|
)(props)
|
19960
19989
|
},
|
package/dist/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, 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, 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-PFCQ55ZF.mjs';
|
package/package.json
CHANGED
@@ -12,7 +12,7 @@ import { StyledField } from "./StyledField";
|
|
12
12
|
import { TimeField } from "./TimeField";
|
13
13
|
import { getCurrentTime, useCurrentLocale } from "./utils";
|
14
14
|
|
15
|
-
type TimePickerProps = Omit<BoxProps, "defaultValue"> & {
|
15
|
+
type TimePickerProps = Omit<BoxProps, "defaultValue" | "onChange"> & {
|
16
16
|
/** The label. Defaults to a localized version of "Time" */
|
17
17
|
label?: string;
|
18
18
|
/** The name of the form field, if used in a regular form */
|
package/src/input/Combobox.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useRef } from "react";
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
2
2
|
import { AriaComboBoxProps, useComboBox, useFilter } from "react-aria";
|
3
3
|
import { useComboBoxState } from "react-stately";
|
4
4
|
import { ColorSpinner, Input, InputProps, ListBox } from "..";
|
@@ -82,14 +82,17 @@ export function Combobox<T extends object>({
|
|
82
82
|
}: ComboboxProps<T>) {
|
83
83
|
const { contains } = useFilter({ sensitivity: "base" });
|
84
84
|
|
85
|
-
const inputRef = useRef(null);
|
85
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
86
86
|
const listBoxRef = useRef(null);
|
87
87
|
const popoverRef = useRef(null);
|
88
88
|
|
89
|
+
const inputWidth = useInputWidth(inputRef);
|
90
|
+
|
89
91
|
const state = useComboBoxState({
|
90
92
|
...rest,
|
91
93
|
defaultFilter: contains,
|
92
94
|
allowsEmptyCollection: Boolean(emptyContent),
|
95
|
+
shouldCloseOnBlur: true,
|
93
96
|
});
|
94
97
|
|
95
98
|
const {
|
@@ -111,8 +114,12 @@ export function Combobox<T extends object>({
|
|
111
114
|
{...inputProps}
|
112
115
|
ref={inputRef}
|
113
116
|
label={label}
|
114
|
-
borderBottomLeftRadius={
|
115
|
-
|
117
|
+
borderBottomLeftRadius={
|
118
|
+
state.isOpen && !isLoading ? 0 : borderBottomLeftRadius
|
119
|
+
}
|
120
|
+
borderBottomRightRadius={
|
121
|
+
state.isOpen && !isLoading ? 0 : borderBottomRightRadius
|
122
|
+
}
|
116
123
|
borderTopLeftRadius={borderTopLeftRadius}
|
117
124
|
borderTopRightRadius={borderTopRightRadius}
|
118
125
|
marginBottom={marginBottom}
|
@@ -145,10 +152,10 @@ export function Combobox<T extends object>({
|
|
145
152
|
)
|
146
153
|
}
|
147
154
|
/>
|
148
|
-
{state.isOpen && (
|
155
|
+
{state.isOpen && !isLoading && (
|
149
156
|
<Popover
|
150
157
|
state={state}
|
151
|
-
triggerRef={inputRef}
|
158
|
+
triggerRef={inputRef as any}
|
152
159
|
ref={popoverRef}
|
153
160
|
placement="bottom start"
|
154
161
|
>
|
@@ -157,6 +164,7 @@ export function Combobox<T extends object>({
|
|
157
164
|
state={state}
|
158
165
|
listBoxRef={listBoxRef}
|
159
166
|
emptyContent={emptyContent}
|
167
|
+
maxWidth={inputWidth}
|
160
168
|
>
|
161
169
|
{rest.children}
|
162
170
|
</ListBox>
|
@@ -165,3 +173,28 @@ export function Combobox<T extends object>({
|
|
165
173
|
</>
|
166
174
|
);
|
167
175
|
}
|
176
|
+
|
177
|
+
const useInputWidth = (inputRef: React.RefObject<HTMLInputElement>) => {
|
178
|
+
const [inputWidth, setInputWidth] = useState("auto");
|
179
|
+
useEffect(() => {
|
180
|
+
const onResize = debounce(() => {
|
181
|
+
if (inputRef.current) {
|
182
|
+
setInputWidth(`${inputRef.current.offsetWidth}px`);
|
183
|
+
}
|
184
|
+
}, 67);
|
185
|
+
window.addEventListener("resize", onResize);
|
186
|
+
return () => window.removeEventListener("resize", onResize);
|
187
|
+
}, []);
|
188
|
+
return inputWidth;
|
189
|
+
};
|
190
|
+
|
191
|
+
const debounce = (fn: () => void, ms = 100) => {
|
192
|
+
let timer: any;
|
193
|
+
return () => {
|
194
|
+
clearTimeout(timer);
|
195
|
+
timer = setTimeout(() => {
|
196
|
+
timer = null;
|
197
|
+
fn();
|
198
|
+
}, ms);
|
199
|
+
};
|
200
|
+
};
|
package/src/input/ListBox.tsx
CHANGED
@@ -30,6 +30,7 @@ type ListBoxProps<T> = AriaListBoxProps<T> &
|
|
30
30
|
state: ListState<T> | SelectState<T>;
|
31
31
|
/** UI to render if the collection is empty */
|
32
32
|
emptyContent?: React.ReactNode;
|
33
|
+
maxWidth?: BoxProps["maxWidth"];
|
33
34
|
};
|
34
35
|
|
35
36
|
/**
|
@@ -70,6 +71,7 @@ export function ListBox<T extends object>({
|
|
70
71
|
isLoading,
|
71
72
|
listBoxRef,
|
72
73
|
state,
|
74
|
+
maxWidth,
|
73
75
|
...props
|
74
76
|
}: ListBoxProps<T>) {
|
75
77
|
const { listBoxProps } = useListBox(props, state, listBoxRef);
|
@@ -81,6 +83,7 @@ export function ListBox<T extends object>({
|
|
81
83
|
ref={listBoxRef}
|
82
84
|
sx={styles.container}
|
83
85
|
aria-busy={isLoading}
|
86
|
+
maxWidth={maxWidth}
|
84
87
|
>
|
85
88
|
{state.collection.size === 0 && props.emptyContent}
|
86
89
|
{Array.from(state.collection).map((item) =>
|
@@ -73,7 +73,7 @@ const config = helpers.defineMultiStyleConfig({
|
|
73
73
|
},
|
74
74
|
dateTimeSegment: {
|
75
75
|
color: mode(
|
76
|
-
props.
|
76
|
+
props.isEditable ? "darkGrey" : "dimGrey",
|
77
77
|
props.isPlaceholder ? "whiteAlpha.400" : "white"
|
78
78
|
)(props),
|
79
79
|
},
|