Fix currency autocomplete widget (#1865)
* bump downshift version * Firther refactor for downshift bump * Update tests * Remove unnecessary id property * Remove unnecessary !important
This commit is contained in:
parent
9a7c9a3bc3
commit
d3db86a2d2
9 changed files with 1442 additions and 725 deletions
38
package-lock.json
generated
38
package-lock.json
generated
|
@ -10109,6 +10109,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"compute-scroll-into-view": {
|
||||||
|
"version": "1.0.17",
|
||||||
|
"resolved": "https://registry.npmjs.org/compute-scroll-into-view/-/compute-scroll-into-view-1.0.17.tgz",
|
||||||
|
"integrity": "sha512-j4dx+Fb0URmzbwwMUrhqWM2BEWHdFGx+qZ9qqASHRPqvTYdqvWnHg0H1hIbcyLnvgnoNAVMlwkepyqM3DaIFUg=="
|
||||||
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
|
@ -11880,9 +11885,36 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"downshift": {
|
"downshift": {
|
||||||
"version": "1.31.16",
|
"version": "6.1.7",
|
||||||
"resolved": "https://registry.npmjs.org/downshift/-/downshift-1.31.16.tgz",
|
"resolved": "https://registry.npmjs.org/downshift/-/downshift-6.1.7.tgz",
|
||||||
"integrity": "sha512-RskXmiGSoz0EHAyBrmTBGSLHg6+NYDGuLu2W3GpmuOe6hmZEWhCiQrq5g6DWzhnUaJD41xHbbfC6j1Fe86YqgA=="
|
"integrity": "sha512-cVprZg/9Lvj/uhYRxELzlu1aezRcgPWBjTvspiGTVEU64gF5pRdSRKFVLcxqsZC637cLAGMbL40JavEfWnqgNg==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.14.8",
|
||||||
|
"compute-scroll-into-view": "^1.0.17",
|
||||||
|
"prop-types": "^15.7.2",
|
||||||
|
"react-is": "^17.0.2",
|
||||||
|
"tslib": "^2.3.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": {
|
||||||
|
"version": "7.17.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.17.2.tgz",
|
||||||
|
"integrity": "sha512-hzeyJyMA1YGdJTuWU0e/j4wKXrU4OMFvY2MSlaI9B7VQb0r5cxTE3EAIS2Q7Tn2RIcDkRvTA/v2JsAEhxe99uw==",
|
||||||
|
"requires": {
|
||||||
|
"regenerator-runtime": "^0.13.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"regenerator-runtime": {
|
||||||
|
"version": "0.13.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz",
|
||||||
|
"integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA=="
|
||||||
|
},
|
||||||
|
"tslib": {
|
||||||
|
"version": "2.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
|
||||||
|
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"duplexer": {
|
"duplexer": {
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
"crc-32": "^1.2.0",
|
"crc-32": "^1.2.0",
|
||||||
"currency-codes": "^2.1.0",
|
"currency-codes": "^2.1.0",
|
||||||
"cypress-mailhog": "^1.3.0",
|
"cypress-mailhog": "^1.3.0",
|
||||||
"downshift": "^1.31.16",
|
"downshift": "^6.1.7",
|
||||||
"editorjs-inline-tool": "^0.4.0",
|
"editorjs-inline-tool": "^0.4.0",
|
||||||
"editorjs-undo": "^0.1.4",
|
"editorjs-undo": "^0.1.4",
|
||||||
"faker": "^5.1.0",
|
"faker": "^5.1.0",
|
||||||
|
|
|
@ -110,10 +110,7 @@ const AutocompleteSelectMenu: React.FC<AutocompleteSelectMenuProps> = props => {
|
||||||
return (
|
return (
|
||||||
<DebounceAutocomplete debounceFn={onInputChange}>
|
<DebounceAutocomplete debounceFn={onInputChange}>
|
||||||
{debounceFn => (
|
{debounceFn => (
|
||||||
<Downshift
|
<Downshift onSelect={handleChange}>
|
||||||
itemToString={item => (item ? item.label : "")}
|
|
||||||
onSelect={handleChange}
|
|
||||||
>
|
|
||||||
{({ getItemProps, isOpen, openMenu, closeMenu, selectItem }) => (
|
{({ getItemProps, isOpen, openMenu, closeMenu, selectItem }) => (
|
||||||
<div
|
<div
|
||||||
className={classes.container}
|
className={classes.container}
|
||||||
|
@ -130,6 +127,7 @@ const AutocompleteSelectMenu: React.FC<AutocompleteSelectMenuProps> = props => {
|
||||||
closeMenu();
|
closeMenu();
|
||||||
setMenuPath([]);
|
setMenuPath([]);
|
||||||
setInputValue(displayValue || "");
|
setInputValue(displayValue || "");
|
||||||
|
debounceFn("");
|
||||||
},
|
},
|
||||||
onChange: event => {
|
onChange: event => {
|
||||||
debounceFn(event.target.value);
|
debounceFn(event.target.value);
|
||||||
|
@ -156,7 +154,7 @@ const AutocompleteSelectMenu: React.FC<AutocompleteSelectMenuProps> = props => {
|
||||||
<MenuItem
|
<MenuItem
|
||||||
component="div"
|
component="div"
|
||||||
{...getItemProps({
|
{...getItemProps({
|
||||||
item: null
|
item: "Back"
|
||||||
})}
|
})}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setMenuPath(menuPath.slice(0, menuPath.length - 2))
|
setMenuPath(menuPath.slice(0, menuPath.length - 2))
|
||||||
|
@ -171,10 +169,10 @@ const AutocompleteSelectMenu: React.FC<AutocompleteSelectMenuProps> = props => {
|
||||||
: options
|
: options
|
||||||
).map((suggestion, index) => (
|
).map((suggestion, index) => (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
data-test-id={testIds[index]}
|
data-test-id={!!testIds ? testIds[index] : ""}
|
||||||
key={suggestion.value}
|
key={`${suggestion.value}:${index}`}
|
||||||
component="div"
|
component="div"
|
||||||
{...getItemProps({ item: suggestion })}
|
{...getItemProps({ item: suggestion.value ?? "" })}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
suggestion.value
|
suggestion.value
|
||||||
? selectItem(suggestion.value)
|
? selectItem(suggestion.value)
|
||||||
|
|
|
@ -132,7 +132,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
|
|
||||||
const handleSelect = (
|
const handleSelect = (
|
||||||
item: string,
|
item: string,
|
||||||
downshiftOpts?: ControllerStateAndHelpers
|
downshiftOpts?: ControllerStateAndHelpers<string>
|
||||||
) => {
|
) => {
|
||||||
if (downshiftOpts) {
|
if (downshiftOpts) {
|
||||||
downshiftOpts.reset({ inputValue: "", isOpen: true });
|
downshiftOpts.reset({ inputValue: "", isOpen: true });
|
||||||
|
@ -165,6 +165,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
getItemProps,
|
getItemProps,
|
||||||
isOpen,
|
isOpen,
|
||||||
toggleMenu,
|
toggleMenu,
|
||||||
|
getMenuProps,
|
||||||
highlightedIndex,
|
highlightedIndex,
|
||||||
inputValue
|
inputValue
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -181,24 +182,26 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
<div className={classes.container} {...rest}>
|
<div className={classes.container} {...rest}>
|
||||||
<TextField
|
<TextField
|
||||||
InputProps={{
|
InputProps={{
|
||||||
...getInputProps({
|
|
||||||
placeholder
|
|
||||||
}),
|
|
||||||
endAdornment: (
|
endAdornment: (
|
||||||
<div className={classes.adornment}>
|
<div className={classes.adornment}>
|
||||||
{endAdornment}
|
{endAdornment}
|
||||||
<ArrowDropdownIcon />
|
<ArrowDropdownIcon />
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
id: undefined,
|
ref: anchor,
|
||||||
onBlur,
|
onBlur,
|
||||||
onClick: toggleMenu,
|
|
||||||
onFocus: () => {
|
onFocus: () => {
|
||||||
if (fetchOnFocus) {
|
if (fetchOnFocus) {
|
||||||
fetchChoices(inputValue);
|
fetchChoices(inputValue);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
ref: anchor
|
}}
|
||||||
|
inputProps={{
|
||||||
|
...getInputProps({
|
||||||
|
placeholder,
|
||||||
|
onClick: toggleMenu
|
||||||
|
}),
|
||||||
|
...getMenuProps()
|
||||||
}}
|
}}
|
||||||
error={error}
|
error={error}
|
||||||
helperText={helperText}
|
helperText={helperText}
|
||||||
|
|
|
@ -39,7 +39,7 @@ export interface MultiAutocompleteSelectFieldContentProps
|
||||||
choices: MultiAutocompleteChoiceType[];
|
choices: MultiAutocompleteChoiceType[];
|
||||||
displayCustomValue: boolean;
|
displayCustomValue: boolean;
|
||||||
displayValues: MultiAutocompleteChoiceType[];
|
displayValues: MultiAutocompleteChoiceType[];
|
||||||
getItemProps: (options: GetItemPropsOptions) => void;
|
getItemProps: (options: GetItemPropsOptions<string>) => any;
|
||||||
highlightedIndex: number;
|
highlightedIndex: number;
|
||||||
inputValue: string;
|
inputValue: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import React from "react";
|
||||||
import { QuickSearchAction } from "./types";
|
import { QuickSearchAction } from "./types";
|
||||||
|
|
||||||
interface NavigatorSectionProps {
|
interface NavigatorSectionProps {
|
||||||
getItemProps: (options: GetItemPropsOptions) => any;
|
getItemProps: (options: GetItemPropsOptions<QuickSearchAction>) => any;
|
||||||
highlightedIndex: number;
|
highlightedIndex: number;
|
||||||
label: string;
|
label: string;
|
||||||
items: QuickSearchAction[];
|
items: QuickSearchAction[];
|
||||||
|
|
|
@ -105,7 +105,6 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
<DebounceAutocomplete debounceFn={fetchChoices}>
|
<DebounceAutocomplete debounceFn={fetchChoices}>
|
||||||
{debounceFn => (
|
{debounceFn => (
|
||||||
<Downshift
|
<Downshift
|
||||||
defaultInputValue={displayValue}
|
|
||||||
itemToString={() => displayValue || ""}
|
itemToString={() => displayValue || ""}
|
||||||
onInputValueChange={value => debounceFn(value)}
|
onInputValueChange={value => debounceFn(value)}
|
||||||
onSelect={handleChange}
|
onSelect={handleChange}
|
||||||
|
@ -177,9 +176,6 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
|
|
||||||
const commonInputProps = {
|
const commonInputProps = {
|
||||||
...InputProps,
|
...InputProps,
|
||||||
...getInputProps({
|
|
||||||
placeholder
|
|
||||||
}),
|
|
||||||
endAdornment: (
|
endAdornment: (
|
||||||
<div className={classes.adornment}>
|
<div className={classes.adornment}>
|
||||||
<ArrowDropdownIcon />
|
<ArrowDropdownIcon />
|
||||||
|
@ -188,7 +184,6 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
error,
|
error,
|
||||||
id: undefined,
|
id: undefined,
|
||||||
onBlur: handleBlur,
|
onBlur: handleBlur,
|
||||||
onClick: !disabled && toggleMenu,
|
|
||||||
onFocus: () => {
|
onFocus: () => {
|
||||||
if (fetchOnFocus) {
|
if (fetchOnFocus) {
|
||||||
fetchChoices(inputValue);
|
fetchChoices(inputValue);
|
||||||
|
@ -213,6 +208,14 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
<TextFieldComponent
|
<TextFieldComponent
|
||||||
{...nakedInputProps}
|
{...nakedInputProps}
|
||||||
InputProps={commonInputProps}
|
InputProps={commonInputProps}
|
||||||
|
// Downshift doesn't seem to be fully compatible with MUI
|
||||||
|
// https://github.com/downshift-js/downshift/issues/718
|
||||||
|
inputProps={{
|
||||||
|
...getInputProps({
|
||||||
|
placeholder,
|
||||||
|
onClick: !disabled && toggleMenu
|
||||||
|
})
|
||||||
|
}}
|
||||||
error={error}
|
error={error}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
helperText={helperText}
|
helperText={helperText}
|
||||||
|
|
|
@ -41,7 +41,7 @@ export interface SingleAutocompleteSelectFieldContentProps
|
||||||
choices: Array<SingleAutocompleteChoiceType<string, string | JSX.Element>>;
|
choices: Array<SingleAutocompleteChoiceType<string, string | JSX.Element>>;
|
||||||
displayCustomValue: boolean;
|
displayCustomValue: boolean;
|
||||||
emptyOption: boolean;
|
emptyOption: boolean;
|
||||||
getItemProps: (options: GetItemPropsOptions) => any;
|
getItemProps: (options: GetItemPropsOptions<string>) => any;
|
||||||
highlightedIndex: number;
|
highlightedIndex: number;
|
||||||
inputValue: string;
|
inputValue: string;
|
||||||
isCustomValueSelected: boolean;
|
isCustomValueSelected: boolean;
|
||||||
|
@ -94,7 +94,10 @@ const useStyles = makeStyles(
|
||||||
},
|
},
|
||||||
menuItem: {
|
menuItem: {
|
||||||
height: "auto",
|
height: "auto",
|
||||||
whiteSpace: "normal"
|
whiteSpace: "normal",
|
||||||
|
'&[aria-selected="true"]': {
|
||||||
|
backgroundColor: theme.palette.background.default
|
||||||
|
}
|
||||||
},
|
},
|
||||||
progress: {},
|
progress: {},
|
||||||
progressContainer: {
|
progressContainer: {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue