mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
co-authored by
Brian Vaughn
parent
d6e08fe0a8
commit
cddde45806
+8
-13
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user