apply changes on editablevalue on blur feature implemented (#17062)

* apply changes on editablevalue on blur feature implemented

* Removed "Undo" button and unnecessary event.preventDefault()

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
This commit is contained in:
Murat ÇATAL
2020-02-04 11:05:01 -08:00
committed by GitHub
co-authored by Brian Vaughn
parent d6e08fe0a8
commit cddde45806
@@ -8,8 +8,6 @@
*/
import React, {Fragment, useRef} from 'react';
import Button from '../Button';
import ButtonIcon from '../ButtonIcon';
import styles from './EditableValue.css';
import {useEditableValue} from '../hooks';
@@ -51,9 +49,7 @@ export default function EditableValue({
switch (event.key) {
case 'Enter':
if (isValid && hasPendingChanges) {
overrideValueFn(path, parsedValue);
}
applyChanges();
break;
case 'Escape':
reset();
@@ -63,6 +59,12 @@ export default function EditableValue({
}
};
const applyChanges = () => {
if (isValid && hasPendingChanges) {
overrideValueFn(path, parsedValue);
}
};
let placeholder = '';
if (editableValue === undefined) {
placeholder = '(undefined)';
@@ -75,6 +77,7 @@ export default function EditableValue({
<input
autoComplete="new-password"
className={`${isValid ? styles.Input : styles.Invalid} ${className}`}
onBlur={applyChanges}
onChange={handleChange}
onKeyDown={handleKeyDown}
placeholder={placeholder}
@@ -82,14 +85,6 @@ export default function EditableValue({
type="text"
value={editableValue}
/>
{hasPendingChanges && (
<Button
className={styles.ResetButton}
onClick={reset}
title="Reset value">
<ButtonIcon type="undo" />
</Button>
)}
</Fragment>
);
}