Skip to content

Commit 11c6dcd

Browse files
event Handlers in Dropdown do not read current item variable correctly
1 parent 4ae9f71 commit 11c6dcd

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

client/packages/lowcoder/src/comps/comps/buttonComp/dropdownComp.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ const DropdownTmpComp = (function () {
8383
key: option.label + " - " + index,
8484
disabled: option.disabled,
8585
icon: hasIcon && <span>{option.prefixIcon}</span>,
86-
onEvent: option.onEvent,
86+
index,
8787
}));
8888

8989
const menu = (
9090
<Menu
9191
items={items}
92-
onClick={({ key }) => items.find((o) => o.key === key)?.onEvent("click")}
92+
onClick={({ key }) => {
93+
const item = items.find((o) => o.key === key);
94+
item && props.options[item.index]?.onEvent("click");
95+
}}
9396
/>
9497
);
9598

client/packages/lowcoder/src/comps/controls/optionsControl.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ import {
3333
import styled from "styled-components";
3434
import { lastValueIfEqual } from "util/objectUtils";
3535
import { getNextEntityName } from "util/stringUtils";
36-
import { JSONValue } from "util/jsonTypes";
36+
import { JSONObject, JSONValue } from "util/jsonTypes";
3737
import { ButtonEventHandlerControl } from "./eventHandlerControl";
3838
import { ControlItemCompBuilder } from "comps/generators/controlCompBuilder";
3939
import { ColorControl } from "./colorControl";
4040
import { StringStateControl } from "./codeStateControl";
41+
import { reduceInContext } from "../utils/reduceContext";
4142

4243
const OptionTypes = [
4344
{
@@ -312,8 +313,16 @@ export function mapOptionsControl<T extends OptionsControlType>(
312313
}
313314

314315
override reduce(action: CompAction) {
315-
const comp = super.reduce(action);
316+
// TODO: temporary solution condition to fix context issue in dropdown option's events
317+
if (
318+
action.type === CompActionTypes.CUSTOM
319+
&& (action.value as JSONObject).type === 'actionTriggered'
320+
) {
321+
const comp = reduceInContext({ inEventContext: true }, () => super.reduce(action));
322+
return comp;
323+
} else
316324
if (action.type === CompActionTypes.UPDATE_NODES_V2) {
325+
const comp = super.reduce(action)
317326
if (comp.children.data !== this.children.data) {
318327
const sourceArray = comp.children.data.getView();
319328
const dataExample = sourceArray ? sourceArray[0] : undefined;
@@ -323,7 +332,7 @@ export function mapOptionsControl<T extends OptionsControlType>(
323332
}
324333
}
325334
}
326-
return comp;
335+
return super.reduce(action);
327336
}
328337

329338
updateContext(dataExample: JSONValue) {

0 commit comments

Comments
 (0)