@linzjs/step-ag-grid 2.2.2 → 2.3.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/index.js +86 -41
- package/dist/index.js.map +1 -1
- package/dist/src/components/GridSubComponentTextArea.d.ts +7 -2
- package/dist/src/components/gridForm/GridFormDropDown.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +6 -7
- package/dist/src/components/gridForm/GridSubComponentProps.d.ts +6 -0
- package/dist/src/lui/TextInputFormatted.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +87 -42
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridPopoverHook.tsx +0 -1
- package/src/components/GridSubComponentTextArea.tsx +42 -12
- package/src/components/gridForm/GridFormDropDown.tsx +1 -0
- package/src/components/gridForm/GridFormMultiSelect.tsx +50 -24
- package/src/components/gridForm/GridFormTextInput.tsx +6 -0
- package/src/components/gridForm/GridSubComponentProps.ts +6 -0
- package/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.ts +7 -14
- package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +6 -9
- package/src/components/gridPopoverEdit/GridPopoverEditDropDown.ts +8 -15
- package/src/components/gridPopoverEdit/GridPopoverMessage.ts +2 -4
- package/src/components/gridPopoverEdit/GridPopoverTextArea.ts +1 -8
- package/src/components/gridPopoverEdit/GridPopoverTextInput.ts +5 -12
- package/src/lui/TextInputFormatted.tsx +4 -1
- package/src/react-menu3/components/ControlledMenu.tsx +13 -9
- package/src/stories/grid/GridPopoutEditMultiSelect.stories.tsx +16 -7
package/package.json
CHANGED
|
@@ -47,7 +47,6 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopov
|
|
|
47
47
|
saveButtonRef={saveButtonRef}
|
|
48
48
|
menuClassName={"step-ag-grid-react-menu"}
|
|
49
49
|
onClose={(event: MenuCloseEvent) => {
|
|
50
|
-
if (event.reason === "blur") return;
|
|
51
50
|
triggerSave(event.reason).then();
|
|
52
51
|
}}
|
|
53
52
|
viewScroll={"auto"}
|
|
@@ -1,25 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useEffect } from "react";
|
|
2
|
+
import { GridSubComponentProps } from "./gridForm/GridSubComponentProps";
|
|
3
|
+
import { TextInputFormatted } from "../lui/TextInputFormatted";
|
|
2
4
|
|
|
3
|
-
export interface GridSubComponentTextAreaProps {
|
|
4
|
-
|
|
5
|
+
export interface GridSubComponentTextAreaProps extends GridSubComponentProps {
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
maxlength?: number;
|
|
9
|
+
width?: string | number;
|
|
10
|
+
validate: (value: string) => string | null;
|
|
5
11
|
}
|
|
6
12
|
|
|
7
|
-
export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps) => {
|
|
8
|
-
const
|
|
13
|
+
export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps): JSX.Element => {
|
|
14
|
+
const { value, setValue, setValid, triggerSave } = props;
|
|
15
|
+
const validate = useCallback(
|
|
16
|
+
(value: string) => {
|
|
17
|
+
if (props.required && value.length === 0) {
|
|
18
|
+
return `Some text is required`;
|
|
19
|
+
}
|
|
20
|
+
if (props.maxlength && value.length > props.maxlength) {
|
|
21
|
+
return `Text must be no longer than ${props.maxlength} characters`;
|
|
22
|
+
}
|
|
23
|
+
if (props.validate) {
|
|
24
|
+
return props.validate(value);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
},
|
|
28
|
+
[props],
|
|
29
|
+
);
|
|
9
30
|
|
|
10
31
|
useEffect(() => {
|
|
11
|
-
|
|
12
|
-
}, [
|
|
32
|
+
setValid(validate(value) == null);
|
|
33
|
+
}, [setValid, validate, value]);
|
|
13
34
|
|
|
14
35
|
return (
|
|
15
36
|
<div className={"FreeTextInput LuiDeprecatedForms"}>
|
|
16
|
-
<
|
|
17
|
-
autoFocus
|
|
18
|
-
maxLength={10000}
|
|
19
|
-
spellCheck={true}
|
|
37
|
+
<TextInputFormatted
|
|
20
38
|
className={"free-text-input"}
|
|
39
|
+
value={value}
|
|
40
|
+
onMouseEnter={(e) => {
|
|
41
|
+
if (document.activeElement != e.currentTarget) {
|
|
42
|
+
e.currentTarget.focus();
|
|
43
|
+
e.currentTarget.selectionStart = e.currentTarget.value.length;
|
|
44
|
+
}
|
|
45
|
+
}}
|
|
21
46
|
onChange={(e) => setValue(e.target.value)}
|
|
22
|
-
|
|
47
|
+
error={validate(value)}
|
|
48
|
+
inputProps={{
|
|
49
|
+
autoFocus: true,
|
|
50
|
+
placeholder: props.placeholder,
|
|
51
|
+
onKeyDown: async (e) => e.key === "Enter" && triggerSave().then(),
|
|
52
|
+
}}
|
|
23
53
|
/>
|
|
24
54
|
</div>
|
|
25
55
|
);
|
|
@@ -38,6 +38,7 @@ export interface GridFormPopoutDropDownProps<RowType extends GridBaseRow, ValueT
|
|
|
38
38
|
| "GridPopoverEditDropDown-containerSmall"
|
|
39
39
|
| "GridPopoverEditDropDown-containerMedium"
|
|
40
40
|
| "GridPopoverEditDropDown-containerLarge"
|
|
41
|
+
| "GridPopoverEditDropDown-containerUnlimited"
|
|
41
42
|
| string
|
|
42
43
|
| undefined;
|
|
43
44
|
filtered?: "local" | "reload";
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import "../../styles/GridFormMultiSelect.scss";
|
|
2
2
|
|
|
3
3
|
import { MenuItem, MenuDivider, FocusableItem } from "../../react-menu3";
|
|
4
|
-
import { useCallback, useEffect, useRef, useState, KeyboardEvent } from "react";
|
|
4
|
+
import { useCallback, useEffect, useRef, useState, KeyboardEvent, useMemo } from "react";
|
|
5
5
|
import { GridBaseRow } from "../Grid";
|
|
6
6
|
import { ComponentLoadingWrapper } from "../ComponentLoadingWrapper";
|
|
7
|
-
import { delay,
|
|
7
|
+
import { delay, pick, pickBy } from "lodash-es";
|
|
8
8
|
import { LuiCheckboxInput } from "@linzjs/lui";
|
|
9
9
|
import { useGridPopoverHook } from "../GridPopoverHook";
|
|
10
10
|
import { MenuSeparatorString } from "./GridFormDropDown";
|
|
11
11
|
import { CellEditorCommon, CellParams } from "../GridCell";
|
|
12
12
|
import { ClickEvent } from "../../react-menu3/types";
|
|
13
|
+
import { GridSubComponentProps } from "./GridSubComponentProps";
|
|
13
14
|
|
|
14
15
|
interface MultiFinalSelectOption<ValueType> {
|
|
15
16
|
value: ValueType;
|
|
16
17
|
label?: JSX.Element | string;
|
|
17
|
-
subComponent?: (props: any
|
|
18
|
+
subComponent?: (props: any) => JSX.Element;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export type MultiSelectOption<ValueType> = ValueType | MultiFinalSelectOption<ValueType>;
|
|
21
22
|
|
|
22
|
-
export interface
|
|
23
|
-
|
|
24
|
-
values: Record<string, any>;
|
|
23
|
+
export interface SelectedOptionResult<ValueType> extends MultiFinalSelectOption<ValueType> {
|
|
24
|
+
subValue: any;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType> extends CellEditorCommon {
|
|
@@ -30,41 +30,63 @@ export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType
|
|
|
30
30
|
| "GridMultiSelect-containerSmall"
|
|
31
31
|
| "GridMultiSelect-containerMedium"
|
|
32
32
|
| "GridMultiSelect-containerLarge"
|
|
33
|
+
| "GridMultiSelect-containerUnlimited"
|
|
33
34
|
| string
|
|
34
35
|
| undefined;
|
|
35
36
|
filtered?: boolean;
|
|
36
37
|
filterPlaceholder?: string;
|
|
37
|
-
onSave?: (
|
|
38
|
+
onSave?: (selectedRows: RowType[], selectedOptions: SelectedOptionResult<ValueType>[]) => Promise<boolean>;
|
|
38
39
|
options:
|
|
39
40
|
| MultiSelectOption<ValueType>[]
|
|
40
41
|
| ((selectedRows: RowType[]) => Promise<MultiSelectOption<ValueType>[]> | MultiSelectOption<ValueType>[]);
|
|
41
|
-
initialSelectedValues?: (selectedRows: RowType[]) => any[]
|
|
42
|
+
initialSelectedValues?: (selectedRows: RowType[]) => any[] | Record<string, any>;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
|
|
45
46
|
props: GridFormMultiSelectProps<RowType, ValueType>,
|
|
46
47
|
) => {
|
|
47
48
|
const { selectedRows } = props as unknown as CellParams<RowType>;
|
|
49
|
+
|
|
50
|
+
const initialiseValues = useMemo(
|
|
51
|
+
() => props.initialSelectedValues && props.initialSelectedValues(selectedRows),
|
|
52
|
+
[props, selectedRows],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const subComponentIsValid = useRef<Record<string, boolean>>({});
|
|
56
|
+
const [subSelectedValues, setSubSelectedValues] = useState<Record<string, any>>(
|
|
57
|
+
initialiseValues && !Array.isArray(initialiseValues)
|
|
58
|
+
? pickBy(initialiseValues, (value) => typeof value !== "boolean")
|
|
59
|
+
: {},
|
|
60
|
+
);
|
|
61
|
+
const [selectedValues, setSelectedValues] = useState<any[]>(() =>
|
|
62
|
+
initialiseValues ? (Array.isArray(initialiseValues) ? initialiseValues : Object.keys(initialiseValues)) : [],
|
|
63
|
+
);
|
|
64
|
+
|
|
48
65
|
const [filter, setFilter] = useState("");
|
|
49
66
|
const [filteredValues, setFilteredValues] = useState<any[]>([]);
|
|
50
67
|
const optionsInitialising = useRef(false);
|
|
51
68
|
const [options, setOptions] = useState<MultiFinalSelectOption<ValueType>[]>();
|
|
52
|
-
const subSelectedValues = useRef<Record<string, any>>({});
|
|
53
|
-
const [selectedValues, setSelectedValues] = useState<any[]>(() =>
|
|
54
|
-
props.initialSelectedValues ? props.initialSelectedValues(selectedRows) : [],
|
|
55
|
-
);
|
|
56
69
|
|
|
57
70
|
const save = useCallback(
|
|
58
71
|
async (selectedRows: RowType[]): Promise<boolean> => {
|
|
59
|
-
const values: Record<string, any> = fromPairs(
|
|
60
|
-
selectedValues.map((value) => [value, subSelectedValues.current[value] ?? true]),
|
|
61
|
-
);
|
|
62
72
|
if (props.onSave) {
|
|
63
|
-
|
|
73
|
+
const validations = pick(subComponentIsValid.current, selectedValues);
|
|
74
|
+
const notValid = Object.values(validations).some((v) => !v);
|
|
75
|
+
if (notValid) return false;
|
|
76
|
+
|
|
77
|
+
const selectedOptions = selectedValues.map((row) => (options ?? []).find((opt) => opt.value == row)) ?? [];
|
|
78
|
+
const selectedResults = selectedOptions.map(
|
|
79
|
+
(selectedOption) =>
|
|
80
|
+
({
|
|
81
|
+
...selectedOption,
|
|
82
|
+
subValue: subSelectedValues[`${selectedOption?.value}`],
|
|
83
|
+
} as SelectedOptionResult<ValueType>),
|
|
84
|
+
);
|
|
85
|
+
return await props.onSave(selectedRows, selectedResults);
|
|
64
86
|
}
|
|
65
87
|
return true;
|
|
66
88
|
},
|
|
67
|
-
[props, selectedValues],
|
|
89
|
+
[options, props, selectedValues, subSelectedValues],
|
|
68
90
|
);
|
|
69
91
|
|
|
70
92
|
// Load up options list if it's async function
|
|
@@ -188,14 +210,18 @@ export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
|
|
|
188
210
|
<FocusableItem className={"LuiDeprecatedForms"} key={`${item.value}_subcomponent`}>
|
|
189
211
|
{(ref: any) =>
|
|
190
212
|
item.subComponent &&
|
|
191
|
-
item.subComponent(
|
|
192
|
-
{
|
|
193
|
-
setValue: (value: any) => {
|
|
194
|
-
subSelectedValues.current[item.value as string] = value;
|
|
195
|
-
},
|
|
196
|
-
},
|
|
213
|
+
item.subComponent({
|
|
197
214
|
ref,
|
|
198
|
-
|
|
215
|
+
value: subSelectedValues[`${item.value}`],
|
|
216
|
+
setValue: (value: any) => {
|
|
217
|
+
subSelectedValues[`${item.value}`] = value;
|
|
218
|
+
setSubSelectedValues({ ...subSelectedValues });
|
|
219
|
+
},
|
|
220
|
+
setValid: (valid: boolean) => {
|
|
221
|
+
subComponentIsValid.current[`${item.value}`] = valid;
|
|
222
|
+
},
|
|
223
|
+
triggerSave,
|
|
224
|
+
} as GridSubComponentProps)
|
|
199
225
|
}
|
|
200
226
|
</FocusableItem>
|
|
201
227
|
)}
|
|
@@ -63,6 +63,12 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(_props: GridFormT
|
|
|
63
63
|
onChange={(e) => setValue(e.target.value)}
|
|
64
64
|
error={invalid()}
|
|
65
65
|
formatted={props.units}
|
|
66
|
+
onMouseEnter={(e) => {
|
|
67
|
+
if (document.activeElement != e.currentTarget) {
|
|
68
|
+
e.currentTarget.focus();
|
|
69
|
+
e.currentTarget.selectionStart = e.currentTarget.value.length;
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
66
72
|
inputProps={{
|
|
67
73
|
style: { width: "100%" },
|
|
68
74
|
placeholder: props.placeholder,
|
|
@@ -7,18 +7,11 @@ export const GridPopoutEditMultiSelect = <RowType extends GridBaseRow, ValueType
|
|
|
7
7
|
colDef: GenericCellColDef<RowType>,
|
|
8
8
|
props: GenericCellEditorProps<GridFormMultiSelectProps<RowType, ValueType>>,
|
|
9
9
|
): ColDefT<RowType> =>
|
|
10
|
-
GridCell(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
GridCell(colDef, {
|
|
11
|
+
editor: GridFormMultiSelect,
|
|
12
|
+
...props,
|
|
13
|
+
editorParams: {
|
|
14
|
+
className: "GridMultiSelect-containerMedium",
|
|
15
|
+
...(props.editorParams as GridFormMultiSelectProps<RowType, ValueType>),
|
|
15
16
|
},
|
|
16
|
-
|
|
17
|
-
editor: GridFormMultiSelect,
|
|
18
|
-
...props,
|
|
19
|
-
editorParams: {
|
|
20
|
-
className: "GridMultiSelect-containerMedium",
|
|
21
|
-
...(props.editorParams as GridFormMultiSelectProps<RowType, ValueType>),
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
);
|
|
17
|
+
});
|
|
@@ -7,8 +7,8 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
|
|
|
7
7
|
export const GridPopoverEditBearingLike = <RowType extends GridBaseRow>(
|
|
8
8
|
colDef: GenericCellColDef<RowType>,
|
|
9
9
|
props: GenericCellEditorProps<GridFormEditBearingProps<RowType>>,
|
|
10
|
-
): ColDefT<RowType> =>
|
|
11
|
-
|
|
10
|
+
): ColDefT<RowType> =>
|
|
11
|
+
GridCell(
|
|
12
12
|
{
|
|
13
13
|
initialWidth: 65,
|
|
14
14
|
maxWidth: 150,
|
|
@@ -20,13 +20,12 @@ export const GridPopoverEditBearingLike = <RowType extends GridBaseRow>(
|
|
|
20
20
|
...props,
|
|
21
21
|
},
|
|
22
22
|
);
|
|
23
|
-
};
|
|
24
23
|
|
|
25
24
|
export const GridPopoverEditBearing = <RowType extends GridBaseRow>(
|
|
26
25
|
colDef: GenericCellColDef<RowType>,
|
|
27
26
|
props: GenericCellEditorProps<GridFormEditBearingProps<RowType>>,
|
|
28
|
-
): ColDefT<RowType> =>
|
|
29
|
-
|
|
27
|
+
): ColDefT<RowType> =>
|
|
28
|
+
GridPopoverEditBearingLike(
|
|
30
29
|
{ valueFormatter: bearingValueFormatter, ...colDef },
|
|
31
30
|
{
|
|
32
31
|
multiEdit: !!props.multiEdit,
|
|
@@ -42,13 +41,12 @@ export const GridPopoverEditBearing = <RowType extends GridBaseRow>(
|
|
|
42
41
|
},
|
|
43
42
|
},
|
|
44
43
|
);
|
|
45
|
-
};
|
|
46
44
|
|
|
47
45
|
export const GridPopoverEditBearingCorrection = <RowType extends GridBaseRow>(
|
|
48
46
|
colDef: GenericCellColDef<RowType>,
|
|
49
47
|
props: GenericCellEditorProps<GridFormEditBearingProps<RowType>>,
|
|
50
|
-
): ColDefT<RowType> =>
|
|
51
|
-
|
|
48
|
+
): ColDefT<RowType> =>
|
|
49
|
+
GridPopoverEditBearingLike(
|
|
52
50
|
{ valueFormatter: bearingCorrectionValueFormatter, ...colDef },
|
|
53
51
|
{
|
|
54
52
|
multiEdit: !!props.multiEdit,
|
|
@@ -64,4 +62,3 @@ export const GridPopoverEditBearingCorrection = <RowType extends GridBaseRow>(
|
|
|
64
62
|
},
|
|
65
63
|
},
|
|
66
64
|
);
|
|
67
|
-
};
|
|
@@ -7,19 +7,12 @@ export const GridPopoverEditDropDown = <RowType extends GridBaseRow, ValueType>(
|
|
|
7
7
|
colDef: GenericCellColDef<RowType>,
|
|
8
8
|
props: GenericCellEditorProps<GridFormPopoutDropDownProps<RowType, ValueType>>,
|
|
9
9
|
): ColDefT<RowType> =>
|
|
10
|
-
GridCell(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
GridCell(colDef, {
|
|
11
|
+
editor: GridFormDropDown,
|
|
12
|
+
...props,
|
|
13
|
+
editorParams: {
|
|
14
|
+
// Defaults to medium size container
|
|
15
|
+
className: "GridPopoverEditDropDown-containerMedium",
|
|
16
|
+
...(props.editorParams as GridFormPopoutDropDownProps<RowType, ValueType>),
|
|
15
17
|
},
|
|
16
|
-
|
|
17
|
-
editor: GridFormDropDown,
|
|
18
|
-
...props,
|
|
19
|
-
editorParams: {
|
|
20
|
-
// Defaults to medium size container
|
|
21
|
-
className: "GridPopoverEditDropDown-containerMedium",
|
|
22
|
-
...(props.editorParams as GridFormPopoutDropDownProps<RowType, ValueType>),
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
);
|
|
18
|
+
});
|
|
@@ -6,10 +6,9 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
|
|
|
6
6
|
export const GridPopoverMessage = <RowType extends GridBaseRow>(
|
|
7
7
|
colDef: GenericCellColDef<RowType>,
|
|
8
8
|
props: GenericCellEditorProps<GridFormMessageProps<RowType>>,
|
|
9
|
-
): ColDefT<RowType> =>
|
|
10
|
-
|
|
9
|
+
): ColDefT<RowType> =>
|
|
10
|
+
GridCell(
|
|
11
11
|
{
|
|
12
|
-
maxWidth: 140,
|
|
13
12
|
...colDef,
|
|
14
13
|
cellRendererParams: {
|
|
15
14
|
singleClickEdit: true,
|
|
@@ -21,4 +20,3 @@ export const GridPopoverMessage = <RowType extends GridBaseRow>(
|
|
|
21
20
|
...props,
|
|
22
21
|
},
|
|
23
22
|
);
|
|
24
|
-
};
|
|
@@ -6,11 +6,4 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
|
|
|
6
6
|
export const GridPopoverTextArea = <RowType extends GridBaseRow>(
|
|
7
7
|
colDef: GenericCellColDef<RowType>,
|
|
8
8
|
params: GenericCellEditorProps<GridFormTextAreaProps<RowType>>,
|
|
9
|
-
): ColDefT<RowType> =>
|
|
10
|
-
GridCell(
|
|
11
|
-
{
|
|
12
|
-
maxWidth: 260,
|
|
13
|
-
...colDef,
|
|
14
|
-
},
|
|
15
|
-
{ editor: GridFormTextArea, ...params },
|
|
16
|
-
);
|
|
9
|
+
): ColDefT<RowType> => GridCell(colDef, { editor: GridFormTextArea, ...params });
|
|
@@ -6,15 +6,8 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
|
|
|
6
6
|
export const GridPopoverTextInput = <RowType extends GridBaseRow>(
|
|
7
7
|
colDef: GenericCellColDef<RowType>,
|
|
8
8
|
params: GenericCellEditorProps<GridFormTextInputProps<RowType>>,
|
|
9
|
-
): ColDefT<RowType> =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
editor: GridFormTextInput,
|
|
17
|
-
...params,
|
|
18
|
-
},
|
|
19
|
-
);
|
|
20
|
-
};
|
|
9
|
+
): ColDefT<RowType> =>
|
|
10
|
+
GridCell(colDef, {
|
|
11
|
+
editor: GridFormTextInput,
|
|
12
|
+
...params,
|
|
13
|
+
});
|
|
@@ -16,6 +16,8 @@ export interface LuiTextInputProps {
|
|
|
16
16
|
|
|
17
17
|
placeholder?: string;
|
|
18
18
|
formatted?: string;
|
|
19
|
+
|
|
20
|
+
onMouseEnter?: (e: React.MouseEvent<HTMLTextAreaElement>) => void;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export const TextInputFormatted = (props: LuiTextInputProps): JSX.Element => {
|
|
@@ -33,7 +35,8 @@ export const TextInputFormatted = (props: LuiTextInputProps): JSX.Element => {
|
|
|
33
35
|
type={"text"}
|
|
34
36
|
className={"LuiTextInput-input"}
|
|
35
37
|
min="0"
|
|
36
|
-
|
|
38
|
+
spellCheck={true}
|
|
39
|
+
defaultValue={props.value}
|
|
37
40
|
onChange={props.onChange}
|
|
38
41
|
{...props.inputProps}
|
|
39
42
|
/>
|
|
@@ -76,16 +76,16 @@ export const ControlledMenuFr = (
|
|
|
76
76
|
],
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
-
const
|
|
80
|
-
(
|
|
81
|
-
hasParentClass("szh-menu--state-open",
|
|
82
|
-
(closeMenuExclusionClassName && hasParentClass(closeMenuExclusionClassName,
|
|
79
|
+
const isWithinMenu = useCallback(
|
|
80
|
+
(target: EventTarget | null) =>
|
|
81
|
+
hasParentClass("szh-menu--state-open", target as Node) ||
|
|
82
|
+
(closeMenuExclusionClassName && hasParentClass(closeMenuExclusionClassName, target as Node)),
|
|
83
83
|
[closeMenuExclusionClassName],
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
const handleScreenEventForSave = useCallback(
|
|
87
87
|
(ev: MouseEvent) => {
|
|
88
|
-
if (!
|
|
88
|
+
if (!isWithinMenu(ev.target)) {
|
|
89
89
|
ev.preventDefault();
|
|
90
90
|
ev.stopPropagation();
|
|
91
91
|
// FIXME There's an issue in React17
|
|
@@ -107,17 +107,17 @@ export const ControlledMenuFr = (
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
|
-
[
|
|
110
|
+
[isWithinMenu, onClose, saveButtonRef, skipOpen],
|
|
111
111
|
);
|
|
112
112
|
|
|
113
113
|
const handleScreenEventForCancel = useCallback(
|
|
114
114
|
(ev: MouseEvent) => {
|
|
115
|
-
if (!
|
|
115
|
+
if (!isWithinMenu(ev.target)) {
|
|
116
116
|
ev.preventDefault();
|
|
117
117
|
ev.stopPropagation();
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
|
-
[
|
|
120
|
+
[isWithinMenu],
|
|
121
121
|
);
|
|
122
122
|
|
|
123
123
|
useEffect(() => {
|
|
@@ -183,7 +183,11 @@ export const ControlledMenuFr = (
|
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
const onBlur = (e: FocusEvent) => {
|
|
186
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
isMenuOpen(state) &&
|
|
188
|
+
!e.currentTarget.contains(e.relatedTarget || document.activeElement) &&
|
|
189
|
+
!isWithinMenu(e.relatedTarget)
|
|
190
|
+
) {
|
|
187
191
|
safeCall(onClose, { reason: CloseReason.BLUR });
|
|
188
192
|
|
|
189
193
|
// If a user clicks on the menu button when a menu is open, we need to close the menu.
|
|
@@ -10,7 +10,6 @@ import { Grid, GridProps } from "../../components/Grid";
|
|
|
10
10
|
import { useMemo, useState } from "react";
|
|
11
11
|
import { MenuSeparator } from "../../components/gridForm/GridFormDropDown";
|
|
12
12
|
import { wait } from "../../utils/util";
|
|
13
|
-
import { MultiSelectResult } from "../../components/gridForm/GridFormMultiSelect";
|
|
14
13
|
import { GridSubComponentTextArea } from "../../components/GridSubComponentTextArea";
|
|
15
14
|
import { ColDefT, GridCell } from "../../components/GridCell";
|
|
16
15
|
import { GridPopoutEditMultiSelect } from "../../components/gridPopoverEdit/GridPopoutEditMultiSelect";
|
|
@@ -70,6 +69,7 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
|
|
|
70
69
|
editorParams: {
|
|
71
70
|
filtered: true,
|
|
72
71
|
filterPlaceholder: "Filter position",
|
|
72
|
+
className: "GridMultiSelect-containerUnlimited",
|
|
73
73
|
options: [
|
|
74
74
|
{ value: "a", label: "Architect" },
|
|
75
75
|
{ value: "b", label: "Developer" },
|
|
@@ -78,15 +78,24 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
|
|
|
78
78
|
{ value: "e", label: "Tester" },
|
|
79
79
|
MenuSeparator,
|
|
80
80
|
{
|
|
81
|
-
value: "
|
|
81
|
+
value: "other",
|
|
82
82
|
label: "Other",
|
|
83
|
-
subComponent: (props) => <GridSubComponentTextArea {...props} />,
|
|
83
|
+
subComponent: (props) => <GridSubComponentTextArea {...props} maxlength={2} />,
|
|
84
84
|
},
|
|
85
85
|
],
|
|
86
|
-
|
|
86
|
+
initialSelectedValues: () => ({
|
|
87
|
+
other: "Hello",
|
|
88
|
+
}),
|
|
89
|
+
onSave: async (selectedRows, selectedOptions) => {
|
|
87
90
|
// eslint-disable-next-line no-console
|
|
88
|
-
console.log(result);
|
|
91
|
+
console.log("multiSelect result", { selectedRows, selectedOptions });
|
|
92
|
+
|
|
89
93
|
await wait(1000);
|
|
94
|
+
const normalValues = selectedOptions.filter((o) => !o.subComponent).map((o) => o.label);
|
|
95
|
+
const subValues = selectedOptions.filter((o) => o.subComponent).map((o) => o.subValue);
|
|
96
|
+
selectedRows.forEach((row) => {
|
|
97
|
+
row.position = [...normalValues, ...subValues].join(", ");
|
|
98
|
+
});
|
|
90
99
|
return true;
|
|
91
100
|
},
|
|
92
101
|
},
|
|
@@ -107,9 +116,9 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
|
|
|
107
116
|
filterPlaceholder: "Filter position",
|
|
108
117
|
initialSelectedValues: (selectedRows) => [selectedRows[0].position2],
|
|
109
118
|
options: Object.entries(positionTwoMap).map(([k, v]) => ({ value: k, label: v })),
|
|
110
|
-
onSave: async (
|
|
119
|
+
onSave: async (selectedRows, selectedOptions) => {
|
|
111
120
|
// eslint-disable-next-line no-console
|
|
112
|
-
console.log(result);
|
|
121
|
+
console.log("multiSelect result", { selectedRows, selectedOptions });
|
|
113
122
|
await wait(1000);
|
|
114
123
|
return true;
|
|
115
124
|
},
|