@@ -35,7 +35,7 @@ export default class FileInput extends Component<Props, State> {
3535 } ;
3636
3737 private get emptyLabel ( ) {
38- return this . props . emptyLabel ?? 'Choose image ...' ;
38+ return this . props . emptyLabel ?? 'Choose file ...' ;
3939 }
4040
4141 componentDidUpdate ( prevProps : Props ) {
@@ -66,9 +66,12 @@ export default class FileInput extends Component<Props, State> {
6666 clear ( ) {
6767 if ( ! this . ref . current ) return ;
6868 this . ref . current . value = '' ;
69- this . updateLabelFromInput ( ) ;
7069 this . props . onChange ?.( null ) ;
7170 this . props . onClear ?.( ) ;
71+ this . setState ( {
72+ label : this . emptyLabel ,
73+ hasFiles : false
74+ } ) ;
7275 }
7376
7477 render ( ) {
@@ -77,7 +80,7 @@ export default class FileInput extends Component<Props, State> {
7780 const { label, hasFiles } = this . state ;
7881
7982 return (
80- < div className = { ` ${ styles [ 'file-input-container' ] } ${ className ? ` ${ className } ` : '' } ` } { ... props } >
83+ < >
8184 { /* hidden real input */ }
8285 < input
8386 ref = { this . ref }
@@ -92,29 +95,28 @@ export default class FileInput extends Component<Props, State> {
9295 } }
9396 />
9497
95- { /* main button */ }
96- < Button
97- className = { styles [ 'file-main' ] }
98- tooltip = { hasFiles ? 'Change file' : 'Choose file' }
99- onClick = { ( ) => this . openPicker ( ) }
100- disabled = { disabled }
101- >
102- < span className = { styles [ 'file-main-inner' ] } >
103- < FontAwesomeIcon icon = { faUpload } />
104- < span className = { styles [ 'file-main-text' ] } > { label } </ span >
105- </ span >
106- </ Button >
107-
108- { /* clear button (X) */ }
109- < Button
110- className = { styles [ 'file-clear' ] }
111- tooltip = 'Usuń'
112- onClick = { ( ) => this . clear ( ) }
113- disabled = { ( disabled || ! hasFiles ) && ! this . props . canClearEmpty }
114- >
115- < FontAwesomeIcon icon = { faXmark } />
116- </ Button >
117- </ div >
98+ < div className = { `${ styles [ 'file-input-container' ] } ${ className ? ` ${ className } ` : '' } ` } { ...props } >
99+ < Button
100+ className = { styles [ 'file-main' ] }
101+ tooltip = { hasFiles ? 'Change file' : 'Choose file' }
102+ onClick = { ( ) => this . openPicker ( ) }
103+ disabled = { disabled }
104+ >
105+ < span className = { styles [ 'file-main-inner' ] } >
106+ < FontAwesomeIcon icon = { faUpload } />
107+ < span className = { styles [ 'file-main-text' ] } > { label } </ span >
108+ </ span >
109+ </ Button >
110+
111+ < Button
112+ tooltip = 'Remove selected files.'
113+ onClick = { ( ) => this . clear ( ) }
114+ disabled = { ( disabled || ! hasFiles ) && ! this . props . canClearEmpty }
115+ >
116+ < FontAwesomeIcon icon = { faXmark } />
117+ </ Button >
118+ </ div >
119+ </ >
118120 ) ;
119121 }
120122}
0 commit comments