Canvas - Clear button bugfix (#53068)

This commit is contained in:
Adela Almasan
2022-08-01 14:40:01 -05:00
committed by GitHub
parent 0d817987ec
commit f2436b15bf
2 changed files with 27 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
import React, { FC, useCallback } from 'react';
import React, { FC, useCallback, useState } from 'react';
import {
FieldNamePickerConfigSettings,
@@ -30,6 +30,9 @@ export const TextDimensionEditor: FC<StandardEditorProps<TextDimensionConfig, Te
const { value, context, onChange } = props;
const labelWidth = 9;
// force re-render on clear fixed text
const [refresh, setRefresh] = useState(0);
const onModeChange = useCallback(
(mode) => {
onChange({
@@ -56,15 +59,11 @@ export const TextDimensionEditor: FC<StandardEditorProps<TextDimensionConfig, Te
...value,
fixed,
});
},
[onChange, value]
);
const onClearFixedText = () => {
// Need to first change to field in order to clear fixed value in editor
onChange({ mode: TextDimensionMode.Field, fixed: '', field: '' });
onChange({ mode: TextDimensionMode.Fixed, fixed: '', field: '' });
};
setRefresh(refresh + 1);
},
[onChange, refresh, value]
);
const mode = value?.mode ?? TextDimensionMode.Fixed;
@@ -88,19 +87,19 @@ export const TextDimensionEditor: FC<StandardEditorProps<TextDimensionConfig, Te
</InlineFieldRow>
)}
{mode === TextDimensionMode.Fixed && (
<InlineFieldRow>
<InlineFieldRow key={refresh}>
<InlineField label={'Value'} labelWidth={labelWidth} grow={true}>
<>
<StringValueEditor
context={context}
value={value?.fixed}
onChange={onFixedChange}
item={dummyStringSettings}
/>
{value?.fixed && (
<Button icon="times" variant="secondary" fill="text" size="sm" onClick={onClearFixedText} />
)}
</>
<StringValueEditor
context={context}
value={value?.fixed}
onChange={onFixedChange}
item={dummyStringSettings}
suffix={
value?.fixed && (
<Button icon="times" variant="secondary" fill="text" size="sm" onClick={() => onFixedChange('')} />
)
}
/>
</InlineField>
</InlineFieldRow>
)}