Skip to content

Commit 4dcdebe

Browse files
feat: added hasControlInside prop to enable/disabe button like behavior - focus and role on the wrapper (#521)
1 parent ef0a511 commit 4dcdebe

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/AjaxUploader.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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}

src/Upload.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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;

src/interface.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface UploadProps
4343
styles?: {
4444
input?: React.CSSProperties;
4545
};
46+
hasControlInside?: boolean;
4647
}
4748

4849
export interface UploadProgressEvent extends Partial<ProgressEvent> {

tests/uploader.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)