Skip to content
Snippets Groups Projects
Unverified Commit d1a2294a authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Fix editable text issues (#23532)

parent a6383ba6
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ export type EditableTextAttributes = Omit<
export interface EditableTextProps extends EditableTextAttributes {
initialValue?: string | null;
placeholder?: string;
isOptional?: boolean;
isMultiline?: boolean;
onChange?: (value: string) => void;
"data-testid"?: string;
......@@ -26,6 +27,7 @@ const EditableText = forwardRef(function EditableText(
{
initialValue,
placeholder,
isOptional = false,
isMultiline = false,
onChange,
"data-testid": dataTestId,
......@@ -35,13 +37,16 @@ const EditableText = forwardRef(function EditableText(
) {
const [inputValue, setInputValue] = useState(initialValue ?? "");
const [submitValue, setSubmitValue] = useState(initialValue ?? "");
const displayValue = inputValue ? inputValue : placeholder;
const handleBlur = useCallback(() => {
if (inputValue !== submitValue) {
if (!isOptional && !inputValue) {
setInputValue(submitValue);
} else if (inputValue !== submitValue) {
setSubmitValue(inputValue);
onChange?.(inputValue);
}
}, [inputValue, submitValue, onChange]);
}, [inputValue, submitValue, isOptional, onChange]);
const handleChange = useCallback(
(event: ChangeEvent<HTMLTextAreaElement>) => {
......@@ -63,7 +68,7 @@ const EditableText = forwardRef(function EditableText(
);
return (
<EditableTextRoot {...props} ref={ref} data-value={`${inputValue}\u00A0`}>
<EditableTextRoot {...props} ref={ref} data-value={`${displayValue}\u00A0`}>
<EditableTextArea
value={inputValue}
placeholder={placeholder}
......
......@@ -192,11 +192,8 @@ function SavedQuestionLeftSide(props) {
const onHeaderChange = useCallback(
name => {
if (name !== question.displayName()) {
onSave({
...question.card(),
name,
});
if (name && name !== question.displayName()) {
onSave(question.setDisplayName(name).card());
}
},
[question, onSave],
......
......@@ -51,6 +51,7 @@ export const QuestionInfoSidebar = ({
<EditableText
initialValue={description}
placeholder={t`Description`}
isOptional
isMultiline
onChange={handleSave}
/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment