Skip to content

Commit 73a0d58

Browse files
make table's switch column editable
1 parent c8a85c3 commit 73a0d58

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

client/packages/lowcoder/src/components/table/EditableCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export function EditableCell<T extends JSONValue>(props: EditableCellProps<T>) {
7979
const editable = editViewFn ? props.editable : false;
8080
const { isEditing, setIsEditing } = useContext(TableCellContext);
8181
const value = changeValue ?? baseValue!;
82-
8382
const [tmpValue, setTmpValue] = useState<T | null>(value);
83+
8484
useEffect(() => {
8585
setTmpValue(value);
8686
}, [value]);

client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnSwitchComp.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ const SwitchWrapper = styled.div<{ disabled: boolean }>`
6161
`};
6262
`;
6363

64+
const Wrapper = styled.div`
65+
background: transparent !important;
66+
padding: 0 8px;
67+
`
68+
6469
const childrenMap = {
6570
value: booleanExposingStateControl("value"),
6671
switchState: BoolCodeControl,
@@ -80,18 +85,16 @@ export const SwitchComp = (function () {
8085
const value = props.changeValue ?? getBaseValue(props, dispatch);
8186
const CheckBoxComp = () => {
8287
return (
83-
<SwitchWrapper disabled={props.disabled}>
84-
<Switch
85-
checked={props.value.value || true}
86-
disabled={props.disabled}
87-
ref={props.viewRef}
88-
onChange={(checked) => {
89-
props.value.onChange(checked);
90-
props.onEvent("change");
91-
props.onEvent(checked ? "true" : "false");
92-
}}
93-
/>
94-
</SwitchWrapper>
88+
<Switch
89+
checked={value}
90+
disabled={props.disabled || true}
91+
ref={props.viewRef}
92+
onChange={(checked) => {
93+
props.value.onChange(checked);
94+
props.onEvent("change");
95+
props.onEvent(checked ? "true" : "false");
96+
}}
97+
/>
9598
);
9699
};
97100
return <CheckBoxComp />;
@@ -101,15 +104,22 @@ export const SwitchComp = (function () {
101104
)
102105
.setEditViewFn((props) => {
103106
return (
104-
<Switch
105-
checked={props.value}
106-
disabled={false}
107-
onChange={(checked) => {
108-
props.onChange(checked);
109-
// props.onEvent("change");
110-
// props.onEvent(checked ? "true" : "false");
107+
<Wrapper
108+
onBlur={(e) => {
109+
if (!e.currentTarget?.contains(e.relatedTarget)) {
110+
props.onChangeEnd();
111+
}
111112
}}
112-
/>
113+
>
114+
<Switch
115+
defaultChecked={props.value}
116+
disabled={false}
117+
onChange={(checked) => {
118+
props.onChange(checked);
119+
}}
120+
/>
121+
122+
</Wrapper>
113123
);
114124
})
115125
.setPropertyViewFn((children) => {

0 commit comments

Comments
 (0)