@@ -45,6 +45,7 @@ export class BaseTextField extends React.Component {
4545 spec : PropTypes . object ,
4646 value : PropTypes . any ,
4747 disabled : PropTypes . bool ,
48+ visible : PropTypes . bool ,
4849 onChange : PropTypes . func ,
4950 'data-test' : PropTypes . string ,
5051 }
@@ -54,6 +55,7 @@ export class BaseTextField extends React.Component {
5455
5556 this . state = {
5657 value : this . toStateValue ( this . props . value ) ,
58+ visible : false ,
5759 } ;
5860 }
5961
@@ -105,6 +107,10 @@ export class BaseTextField extends React.Component {
105107 }
106108 }
107109
110+ visibilityToggle ( ) {
111+ this . setState ( { visible : ! this . state . visible } )
112+ }
113+
108114 emitChange ( ) {
109115 return this . props . onChange ( this . fromStateValue ( this . state . value ) ) ;
110116 }
@@ -113,18 +119,22 @@ export class BaseTextField extends React.Component {
113119 const { icon } = this . constructor ;
114120 const { invalid } = this . state ;
115121 const { spec= { } } = this . props ;
116- const wrapperProps = Object . assign ( { } , this . props ) ;
122+ const wrapperProps = Object . assign ( { } , this . props , {
123+ visibilityToggle : ( ) => this . visibilityToggle ( ) ,
124+ visible : this . state . visible ,
125+ } ) ;
117126
118127 if ( invalid ) {
119128 wrapperProps . invalid = invalid ;
120129 }
121130
122131 const inputProps = {
123- className : 'st2-auto-form__field' ,
124- type : spec . secret ? 'password' : 'text' ,
132+ className : spec . secret && ! this . state . visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
133+ type : 'text' ,
125134 placeholder :this . toStateValue ( spec . default ) ,
126135 disabled : this . props . disabled ,
127136 value : this . state . value ,
137+ spellCheck : spec . secret && ! this . state . visible ? false : true ,
128138 onChange : ( e ) => this . handleChange ( e , e . target . value ) ,
129139 'data-test' : this . props [ 'data-test' ] ,
130140 } ;
@@ -135,7 +145,7 @@ export class BaseTextField extends React.Component {
135145
136146 return (
137147 < TextFieldWrapper icon = { icon } { ...wrapperProps } >
138- < input { ...inputProps } />
148+ < input { ...inputProps } />
139149 </ TextFieldWrapper >
140150 ) ;
141151 }
@@ -145,19 +155,23 @@ export class BaseTextareaField extends BaseTextField {
145155 render ( ) {
146156 const { icon } = this . constructor ;
147157 const { invalid } = this . state ;
148- const { spec= { } } = this . props ;
158+ const { spec = { } } = this . props ;
149159
150- const wrapperProps = Object . assign ( { } , this . props ) ;
160+ const wrapperProps = Object . assign ( { } , this . props , {
161+ visibilityToggle : ( ) => this . visibilityToggle ( ) ,
162+ visible : this . state . visible ,
163+ } ) ;
151164
152165 if ( invalid ) {
153166 wrapperProps . invalid = invalid ;
154167 }
155168
156169 const inputProps = {
157- className : 'st2-auto-form__field' ,
170+ className : spec . secret && ! this . state . visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
158171 placeholder : this . toStateValue ( spec . default ) ,
159172 disabled : this . props . disabled ,
160173 value : this . state . value ,
174+ spellCheck : spec . secret && ! this . state . visible ? false : true ,
161175 onChange : ( e ) => this . handleChange ( e , e . target . value ) ,
162176 minRows : 1 ,
163177 maxRows : 10 ,
@@ -170,7 +184,7 @@ export class BaseTextareaField extends BaseTextField {
170184
171185 return (
172186 < TextFieldWrapper icon = { icon } { ...wrapperProps } >
173- < Textarea { ...inputProps } />
187+ < Textarea { ...inputProps } />
174188 </ TextFieldWrapper >
175189 ) ;
176190 }
0 commit comments