Skip to content

Commit

Permalink
🐛 Store initial value and use it as placeholder + as fallback for chart
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Feb 11, 2021
1 parent 9f38e3a commit 26ad78d
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const LabelInput = ({ value, onChange }: { value: string; onChange: (value: stri
const [inputValue, setInputValue] = useState(value);
const unflushedChanges = useRef(false);

// Save the initial value
const initialValue = useRef(value);

const onChangeDebounced = useMemo(() => {
const callback = _.debounce((val: string) => {
onChange(val);
Expand All @@ -79,7 +82,7 @@ const LabelInput = ({ value, onChange }: { value: string; onChange: (value: stri
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const val = String(e.target.value);
setInputValue(val);
onChangeDebounced(val);
onChangeDebounced(val || initialValue.current);
};

return (
Expand All @@ -96,6 +99,7 @@ const LabelInput = ({ value, onChange }: { value: string; onChange: (value: stri
data-test-subj="indexPattern-label-edit"
value={inputValue}
onChange={handleInputChange}
placeholder={initialValue.current}
/>
</EuiFormRow>
);
Expand Down

0 comments on commit 26ad78d

Please sign in to comment.