File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,7 @@ class AjaxUploader extends Component<UploadProps> {
277277 openFileDialogOnClick,
278278 onMouseEnter,
279279 onMouseLeave,
280+ hasControlInside,
280281 ...otherProps
281282 } = this . props ;
282283 const cls = clsx ( {
@@ -297,10 +298,10 @@ class AjaxUploader extends Component<UploadProps> {
297298 onMouseLeave,
298299 onDrop : this . onFileDrop ,
299300 onDragOver : this . onFileDrop ,
300- tabIndex : '0' ,
301+ tabIndex : hasControlInside ? undefined : '0' ,
301302 } ;
302303 return (
303- < Tag { ...events } className = { cls } role = " button" style = { style } >
304+ < Tag { ...events } className = { cls } role = { hasControlInside ? undefined : ' button' } style = { style } >
304305 < input
305306 { ...pickAttrs ( otherProps , { aria : true , data : true } ) }
306307 id = { id }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Upload extends Component<UploadProps> {
2121 customRequest : null ,
2222 withCredentials : false ,
2323 openFileDialogOnClick : true ,
24+ hasControlInside : false ,
2425 } ;
2526
2627 private uploader : AjaxUpload ;
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ export interface UploadProps
4343 styles ?: {
4444 input ?: React . CSSProperties ;
4545 } ;
46+ hasControlInside ?: boolean ;
4647}
4748
4849export interface UploadProgressEvent extends Partial < ProgressEvent > {
Original file line number Diff line number Diff line change @@ -865,4 +865,18 @@ describe('uploader', () => {
865865 expect ( wrapper . find ( '.bamboo-input' ) . props ( ) . style . color ) . toEqual ( 'red' ) ;
866866 expect ( wrapper . find ( 'input' ) . props ( ) . style . display ) . toBe ( 'none' ) ;
867867 } ) ;
868+
869+ it ( 'Should be focusable and has role=button by default' , ( ) => {
870+ const wrapper = mount ( < Uploader /> ) ;
871+
872+ expect ( wrapper . find ( 'span' ) . props ( ) . tabIndex ) . toBe ( '0' ) ;
873+ expect ( wrapper . find ( 'span' ) . props ( ) . role ) . toBe ( 'button' ) ;
874+ } ) ;
875+
876+ it ( "Should not be focusable and doesn't have role=button with hasControlInside=true" , ( ) => {
877+ const wrapper = mount ( < Uploader hasControlInside /> ) ;
878+
879+ expect ( wrapper . find ( 'span' ) . props ( ) . tabIndex ) . toBe ( undefined ) ;
880+ expect ( wrapper . find ( 'span' ) . props ( ) . role ) . toBe ( undefined ) ;
881+ } ) ;
868882} ) ;
You can’t perform that action at this time.
0 commit comments