@linzjs/step-ag-grid 6.0.0 → 6.1.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 +17 -16
- package/dist/index.js.map +1 -1
- package/dist/step-ag-grid.esm.js +17 -16
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/gridForm/GridFormDropDown.tsx +14 -10
- package/src/react-menu3/components/ControlledMenu.tsx +5 -6
- package/src/stories/grid/FormTest.tsx +7 -3
package/package.json
CHANGED
|
@@ -68,12 +68,15 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
68
68
|
const optionsInitialising = useRef(false);
|
|
69
69
|
const [options, setOptions] = useState<FinalSelectOption[] | null>(null);
|
|
70
70
|
const subComponentIsValid = useRef(false);
|
|
71
|
-
const
|
|
71
|
+
const subComponentInitialValue = useRef<string | null>(null);
|
|
72
|
+
const [subSelectedValue, setSubSelectedValue] = useState<any>(null);
|
|
72
73
|
const [selectedSubComponent, setSelectedSubComponent] = useState<FinalSelectOption | null>(null);
|
|
73
74
|
|
|
74
75
|
const selectItemHandler = useCallback(
|
|
75
76
|
async (value: any, subComponentValue?: any): Promise<boolean> => {
|
|
76
|
-
const hasChanged =
|
|
77
|
+
const hasChanged =
|
|
78
|
+
selectedRows.some((row) => row[field as keyof RowType] !== value) ||
|
|
79
|
+
(subComponentValue !== undefined && subComponentInitialValue.current !== JSON.stringify(subComponentValue));
|
|
77
80
|
if (hasChanged) {
|
|
78
81
|
if (props.onSelectedItem) {
|
|
79
82
|
await props.onSelectedItem({ selectedRows, value, subComponentValue });
|
|
@@ -182,6 +185,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
182
185
|
*/
|
|
183
186
|
const save = useCallback(async () => {
|
|
184
187
|
if (!options) return true;
|
|
188
|
+
|
|
185
189
|
const activeOptions = options.filter((option) => !filteredValues.includes(option.value));
|
|
186
190
|
if (activeOptions.length === 1) {
|
|
187
191
|
await selectItemHandler(activeOptions[0].value);
|
|
@@ -254,14 +258,10 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
254
258
|
value={item.value}
|
|
255
259
|
onClick={(e: ClickEvent) => {
|
|
256
260
|
if (item.subComponent) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
} else {
|
|
262
|
-
// toggle selection on
|
|
263
|
-
setSelectedSubComponent(item);
|
|
264
|
-
}
|
|
261
|
+
// toggle selection
|
|
262
|
+
setSelectedSubComponent(selectedSubComponent === item ? null : item);
|
|
263
|
+
subComponentIsValid.current = true;
|
|
264
|
+
subComponentInitialValue.current = null;
|
|
265
265
|
e.keepOpen = true;
|
|
266
266
|
} else {
|
|
267
267
|
clickItemHandler(
|
|
@@ -289,6 +289,10 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
289
289
|
value: subSelectedValue,
|
|
290
290
|
setValue: (value: any) => {
|
|
291
291
|
setSubSelectedValue(value);
|
|
292
|
+
if (subComponentInitialValue.current === null) {
|
|
293
|
+
// copy the default value of the sub-component so we can change detect on save
|
|
294
|
+
subComponentInitialValue.current = JSON.stringify(value);
|
|
295
|
+
}
|
|
292
296
|
},
|
|
293
297
|
setValid: (valid: boolean) => {
|
|
294
298
|
subComponentIsValid.current = valid;
|
|
@@ -131,20 +131,19 @@ export const ControlledMenuFr = (
|
|
|
131
131
|
let inputEls: HTMLElement[] = [];
|
|
132
132
|
inputElsIterator.forEach((el) => inputEls.push(el));
|
|
133
133
|
inputEls = inputEls.filter((el) => !(el as any).disabled);
|
|
134
|
-
|
|
135
134
|
if (inputEls.length === 0) return;
|
|
136
135
|
const firstInputEl = inputEls[0];
|
|
137
136
|
const lastInputEl = inputEls[inputEls.length - 1];
|
|
138
137
|
if (activeElement !== firstInputEl && activeElement !== lastInputEl) return;
|
|
139
138
|
|
|
140
|
-
const
|
|
139
|
+
const isTextArea = activeElement.nodeName === "TEXTAREA";
|
|
140
|
+
const suppressEnterAutoSave = activeElement.getAttribute("data-disableEnterAutoSave") || isTextArea;
|
|
141
141
|
const invokeSave = (reason: string) => {
|
|
142
|
-
if (!saveButtonRef?.current
|
|
142
|
+
if (!saveButtonRef?.current) return;
|
|
143
143
|
saveButtonRef.current?.setAttribute("data-reason", reason);
|
|
144
144
|
saveButtonRef?.current?.click();
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
const isTextArea = activeElement.nodeName === "TEXTAREA";
|
|
148
147
|
switch (activeElement.nodeName) {
|
|
149
148
|
case "TEXTAREA":
|
|
150
149
|
case "INPUT": {
|
|
@@ -160,7 +159,7 @@ export const ControlledMenuFr = (
|
|
|
160
159
|
invokeSave(ev.shiftKey ? CloseReason.TAB_BACKWARD : CloseReason.TAB_FORWARD);
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
|
-
if (ev.key === "Enter" && !
|
|
162
|
+
if (ev.key === "Enter" && !suppressEnterAutoSave) {
|
|
164
163
|
ev.preventDefault();
|
|
165
164
|
ev.stopPropagation();
|
|
166
165
|
if (isDown) {
|
|
@@ -181,7 +180,7 @@ export const ControlledMenuFr = (
|
|
|
181
180
|
lastTabDownEl.current == activeElement && invokeSave(CloseReason.TAB_FORWARD);
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
|
-
if (ev.key === "Enter" && !
|
|
183
|
+
if (ev.key === "Enter" && !suppressEnterAutoSave) {
|
|
185
184
|
ev.preventDefault();
|
|
186
185
|
ev.stopPropagation();
|
|
187
186
|
if (isDown) {
|
|
@@ -98,9 +98,13 @@ export const FormTest = (props: CellEditorCommon): JSX.Element => {
|
|
|
98
98
|
<LuiTextInput label={"Number"} value={numba} onChange={(e) => setNumba(e.target.value)} />
|
|
99
99
|
</div>
|
|
100
100
|
<div style={{ marginTop: 25 }}>
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
<input
|
|
102
|
+
data-disableEnterAutoSave
|
|
103
|
+
type="button"
|
|
104
|
+
style={{ height: 48 }}
|
|
105
|
+
onClick={() => setShowModal(true)}
|
|
106
|
+
value="Show Modal"
|
|
107
|
+
/>
|
|
104
108
|
</div>
|
|
105
109
|
</div>
|
|
106
110
|
<FormError error={invalid()} />
|