From 0d371438db04ff664e83b8d36c5102be516c769d Mon Sep 17 00:00:00 2001 From: Alex Eng Date: Sat, 5 Mar 2016 17:54:37 +1000 Subject: [PATCH] WIP: reset button --- frontend/src/main/web/src/components/EditableText.js | 7 ++++--- frontend/src/main/web/src/components/TextInput.jsx | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/frontend/src/main/web/src/components/EditableText.js b/frontend/src/main/web/src/components/EditableText.js index f47983b982..ca6e63f34e 100644 --- a/frontend/src/main/web/src/components/EditableText.js +++ b/frontend/src/main/web/src/components/EditableText.js @@ -71,8 +71,6 @@ class EditableText extends Component { !children && classes.text.placeholder ) } - const emptyText = editable ? placeholder : emptyReadOnlyText - const text = children || emptyText if (editable && editing) { return ( this.textInput = ref} - defaultValue={children} /> + value={children} + /> ) } + const emptyText = editable ? placeholder : emptyReadOnlyText + const text = children || emptyText return ( {text} diff --git a/frontend/src/main/web/src/components/TextInput.jsx b/frontend/src/main/web/src/components/TextInput.jsx index 03d22105ac..597f42efbc 100644 --- a/frontend/src/main/web/src/components/TextInput.jsx +++ b/frontend/src/main/web/src/components/TextInput.jsx @@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react' import ReactDOM from 'react-dom' import TextareaAutosize from 'react-textarea-autosize' import { flattenClasses } from 'zanata-ui' +import { debounce } from 'lodash' const classes = { base: { @@ -27,16 +28,20 @@ const classes = { } class TextInput extends Component { - _onBlur (e) { const { onBlur } = this.props - if (onBlur) onBlur(e) + if (onBlur) { + onBlur(e) + } } - _onChange (e) { + _updateText (e) { const { onChange, onChangeText } = this.props if (onChangeText) onChangeText(e.target.value) if (onChange) onChange(e) } + _onChange (e) { + debounce(this._updateText(e), 300) + } _onFocus (e) { const { clearTextOnFocus, onFocus, selectTextOnFocus } = this.props const node = ReactDOM.findDOMNode(this)