File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -175,6 +175,13 @@ import { Input } from 'react-chat-elements'
175175 backgroundColor= ' black'
176176 text= ' Send' / >
177177 }/ >
178+
179+ // clear text eg:
180+ < Input
181+ ref= ' input'
182+ placeholder= " Type here..." / >
183+
184+ this .refs .input .clear ();
178185```
179186
180187#### Input props
Original file line number Diff line number Diff line change @@ -176,16 +176,18 @@ export class App extends Component {
176176 < Input
177177 placeholder = "Mesajınızı buraya yazınız."
178178 defaultValue = ""
179+ ref = 'input'
179180 multiline = { true }
180181 // buttonsFloat='left'
181182 rightButtons = {
182183 < div >
183184 < Button
184185 color = 'white'
185186 backgroundColor = 'black'
186- onClick = { e => {
187+ onClick = { ( e => {
187188 this . addMessage ( ) ;
188- } }
189+ this . refs . input . clear ( ) ;
190+ } ) . bind ( this ) }
189191 icon = { {
190192 component : < FaSearch /> ,
191193 size : 18 ,
Original file line number Diff line number Diff line change @@ -31,6 +31,15 @@ export class Input extends Component {
3131 }
3232 }
3333
34+ clear ( ) {
35+ var event = {
36+ FAKE_EVENT : true ,
37+ target : this . input ,
38+ } ;
39+ this . input . value = '' ;
40+ this . onChange ( event ) ;
41+ }
42+
3443 render ( ) {
3544 return (
3645 < div className = { classNames ( 'rce-container-input' , this . props . className ) } >
@@ -43,6 +52,11 @@ export class Input extends Component {
4352 {
4453 this . props . multiline === false ?
4554 < input
55+ ref = { ( ref ) => {
56+ if ( this . props . inputRef instanceof Function )
57+ this . props . inputRef ( ref ) ;
58+ this . input = ref ;
59+ } }
4660 type = { this . props . type }
4761 className = { classNames ( 'rce-input' ) }
4862 placeholder = { this . props . placeholder }
@@ -51,6 +65,11 @@ export class Input extends Component {
5165 onChange = { this . onChange . bind ( this ) } />
5266 :
5367 < textarea
68+ ref = { ( ref ) => {
69+ if ( this . props . inputRef instanceof Function )
70+ this . props . inputRef ( ref ) ;
71+ this . input = ref ;
72+ } }
5473 type = { this . props . type }
5574 className = { classNames ( 'rce-input' , 'rce-input-textarea' ) }
5675 placeholder = { this . props . placeholder }
@@ -81,6 +100,7 @@ Input.defaultProps = {
81100 maxHeight : 200 ,
82101 autoHeight : true ,
83102 inputStyle : null ,
103+ inputRef : null ,
84104} ;
85105
86106export default Input ;
You can’t perform that action at this time.
0 commit comments