@@ -20,7 +20,7 @@ export class AddUserDialog extends React.PureComponent<IProps, IState> {
2020 constructor ( props : IProps ) {
2121 super ( props )
2222
23- this . onConfirm = this . onConfirm . bind ( this )
23+ this . onSubmit = this . onSubmit . bind ( this )
2424 }
2525
2626 public state = {
@@ -29,8 +29,7 @@ export class AddUserDialog extends React.PureComponent<IProps, IState> {
2929 names : JSON . parse ( localStorage . getItem ( 'names' ) || '[]' ) ,
3030 }
3131
32- @keydown ( 'enter' )
33- private onConfirm ( ) {
32+ private submit = ( ) => {
3433 const name = this . state . value
3534
3635 if ( name . trim ( ) . length < 3 ) {
@@ -46,11 +45,20 @@ export class AddUserDialog extends React.PureComponent<IProps, IState> {
4645 names . splice ( names . indexOf ( name ) )
4746 }
4847
49- this . setState ( { names : [ name , ...names ] , error : false } )
48+ this . setState ( {
49+ value : '' ,
50+ names : [ name , ...names ] ,
51+ error : false ,
52+ } )
53+ }
54+
55+ @keydown ( 'enter' )
56+ private onSubmit ( ) {
57+ this . submit ( )
5058 }
5159
5260 private onInputKeyDown = ( e : React . KeyboardEvent < HTMLInputElement > ) => {
53- if ( e . keyCode === 13 ) return this . onConfirm ( )
61+ if ( e . keyCode === 13 ) return this . submit ( )
5462 }
5563
5664 private onFieldChange = ( value : string ) => {
@@ -63,7 +71,7 @@ export class AddUserDialog extends React.PureComponent<IProps, IState> {
6371
6472 private actions = [
6573 { children : 'Cancel' , onClick : this . props . hide } ,
66- < Button key = "confirm" flat primary onClick = { this . onConfirm } >
74+ < Button key = "confirm" flat primary onClick = { this . submit } >
6775 Add
6876 </ Button > ,
6977 ]
0 commit comments