Skip to content

Commit

Permalink
feat: added hasControlInside prop to enable/disabe button like behavi…
Browse files Browse the repository at this point in the history
…or - focus and role on the wrapper (#521)
  • Loading branch information
vtx-anton-chashchin authored Dec 5, 2023
1 parent ef0a511 commit 4dcdebe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class AjaxUploader extends Component<UploadProps> {
openFileDialogOnClick,
onMouseEnter,
onMouseLeave,
hasControlInside,
...otherProps
} = this.props;
const cls = clsx({
Expand All @@ -297,10 +298,10 @@ class AjaxUploader extends Component<UploadProps> {
onMouseLeave,
onDrop: this.onFileDrop,
onDragOver: this.onFileDrop,
tabIndex: '0',
tabIndex: hasControlInside ? undefined : '0',
};
return (
<Tag {...events} className={cls} role="button" style={style}>
<Tag {...events} className={cls} role={hasControlInside ? undefined : 'button'} style={style}>
<input
{...pickAttrs(otherProps, { aria: true, data: true })}
id={id}
Expand Down
1 change: 1 addition & 0 deletions src/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Upload extends Component<UploadProps> {
customRequest: null,
withCredentials: false,
openFileDialogOnClick: true,
hasControlInside: false,
};

private uploader: AjaxUpload;
Expand Down
1 change: 1 addition & 0 deletions src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface UploadProps
styles?: {
input?: React.CSSProperties;
};
hasControlInside?: boolean;
}

export interface UploadProgressEvent extends Partial<ProgressEvent> {
Expand Down
14 changes: 14 additions & 0 deletions tests/uploader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,18 @@ describe('uploader', () => {
expect(wrapper.find('.bamboo-input').props().style.color).toEqual('red');
expect(wrapper.find('input').props().style.display).toBe('none');
});

it('Should be focusable and has role=button by default', () => {
const wrapper = mount(<Uploader />);

expect(wrapper.find('span').props().tabIndex).toBe('0');
expect(wrapper.find('span').props().role).toBe('button');
});

it("Should not be focusable and doesn't have role=button with hasControlInside=true", () => {
const wrapper = mount(<Uploader hasControlInside />);

expect(wrapper.find('span').props().tabIndex).toBe(undefined);
expect(wrapper.find('span').props().role).toBe(undefined);
});
});

0 comments on commit 4dcdebe

Please sign in to comment.