Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render-setter expression value bug #133

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/playground/src/helpers/mock-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class App extends React.Component {
<FormilyFormItem name="select1" component="Select" label="表单项" />
</FormilyForm>
</Section>
<Section title="原生 DOM" tid="section3">
<Section title="原生 DOM" tid="section4">
<div
style={{
border: "1px solid #ccc",
Expand Down
12 changes: 7 additions & 5 deletions packages/designer/src/setters/render-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { ActionSelect, InputCode } from '@music163/tango-ui';
import { FormItemComponentProps } from '@music163/tango-setting-form';
import { Box } from 'coral-system';
import { value2expressionCode } from '@music163/tango-core';

interface IRenderOption {
label: string;
Expand All @@ -26,10 +27,11 @@ export function RenderSetter({
options = [],
fallbackOption,
}: FormItemComponentProps & RenderSetterProps) {
const [inputValue, setInputValue] = useState(value);

const [inputValue, setInputValue] = useState(() => {
return value2expressionCode(value);
});
useEffect(() => {
setInputValue(value);
setInputValue(value2expressionCode(value));
}, [value]);

const optionsMap = useMemo(() => {
Expand All @@ -53,9 +55,9 @@ export function RenderSetter({
return (
<Box>
<ActionSelect text={text} options={options} onSelect={onSelect} />
{value && (
{inputValue && (
<InputCode
value={value}
value={inputValue}
onChange={(val) => setInputValue(val)}
onBlur={() => onChange(inputValue)}
/>
Expand Down
Loading