@@ -18,6 +18,7 @@ import {
1818import Loading from '../Loading' ;
1919import uid from '../../tools/uniqueId' ;
2020import { ButtonKinds } from '../../prop-types/types' ;
21+ import { keys , matches } from '../../internal/keyboard' ;
2122
2223const { prefix } = settings ;
2324
@@ -308,8 +309,14 @@ export default class FileUploader extends Component {
308309 onChange : PropTypes . func ,
309310
310311 /**
311- * Provide an optional `onClick` hook that is called each time the button is
312- * clicked
312+ * Provide an optional `onDelete` hook that is called when an uploaded item
313+ * is removed
314+ */
315+ onDelete : PropTypes . func ,
316+
317+ /**
318+ * Provide an optional `onClick` hook that is called each time the
319+ * FileUploader is clicked
313320 */
314321 onClick : PropTypes . func ,
315322
@@ -372,12 +379,18 @@ export default class FileUploader extends Component {
372379 }
373380 } ;
374381
375- handleClick = ( evt , index ) => {
376- const filteredArray = this . state . filenames . filter (
377- filename => filename !== this . nodes [ index ] . innerText . trim ( )
378- ) ;
379- this . setState ( { filenames : filteredArray } ) ;
380- this . props . onClick ( evt ) ;
382+ handleClick = ( evt , { index, filenameStatus } ) => {
383+ if ( filenameStatus === 'edit' ) {
384+ evt . stopPropagation ( ) ;
385+ const filteredArray = this . state . filenames . filter (
386+ filename => filename !== this . nodes [ index ] . innerText . trim ( )
387+ ) ;
388+ this . setState ( { filenames : filteredArray } ) ;
389+ if ( this . props . onDelete ) {
390+ this . props . onDelete ( evt ) ;
391+ }
392+ this . props . onClick ( evt ) ;
393+ }
381394 } ;
382395
383396 clearFiles = ( ) => {
@@ -398,6 +411,7 @@ export default class FileUploader extends Component {
398411 accept,
399412 name,
400413 size,
414+ onDelete, // eslint-disable-line no-unused-vars
401415 ...other
402416 } = this . props ;
403417
@@ -440,15 +454,13 @@ export default class FileUploader extends Component {
440454 iconDescription = { iconDescription }
441455 status = { filenameStatus }
442456 onKeyDown = { evt => {
443- if ( evt . which === 13 || evt . which === 32 ) {
444- this . handleClick ( evt , index ) ;
445- }
446- } }
447- onClick = { evt => {
448- if ( filenameStatus === 'edit' ) {
449- this . handleClick ( evt , index ) ;
457+ if ( matches ( evt , [ keys . Enter , keys . Space ] ) ) {
458+ this . handleClick ( evt , { index, filenameStatus } ) ;
450459 }
451460 } }
461+ onClick = { evt =>
462+ this . handleClick ( evt , { index, filenameStatus } )
463+ }
452464 />
453465 </ span >
454466 </ span >
0 commit comments