Skip to content

Commit 71e6d72

Browse files
committed
fix: remove button semantics when click upload is disabled
1 parent 9aba193 commit 71e6d72

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/AjaxUploader.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,15 @@ class AjaxUploader extends Component<UploadProps> {
368368
onMouseLeave,
369369
onDrop: this.onFileDrop,
370370
onDragOver: this.onFileDragOver,
371-
tabIndex: hasControlInside ? undefined : '0',
371+
tabIndex: hasControlInside || !openFileDialogOnClick ? undefined : '0',
372372
};
373373
return (
374-
<Tag {...events} className={cls} role={hasControlInside ? undefined : 'button'} style={style}>
374+
<Tag
375+
{...events}
376+
className={cls}
377+
role={hasControlInside || !openFileDialogOnClick ? undefined : 'button'}
378+
style={style}
379+
>
375380
<input
376381
{...pickAttrs(otherProps, { aria: true, data: true })}
377382
id={id}

‎tests/uploader.spec.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,13 @@ describe('uploader', () => {
13201320
expect(container.querySelector('span')!).not.toHaveAttribute('role', 'button');
13211321
});
13221322

1323+
it("Should not be focusable and doesn't have role=button when click upload is disabled", () => {
1324+
const { container } = render(<Upload openFileDialogOnClick={false} />);
1325+
1326+
expect(container.querySelector('span')!.tabIndex).not.toBe(0);
1327+
expect(container.querySelector('span')!).not.toHaveAttribute('role', 'button');
1328+
});
1329+
13231330
it('should receive same defaultRequest as src', done => {
13241331
const { default: srcRequest } = require('../src/request');
13251332
let receivedDefaultRequest: any;

0 commit comments

Comments
 (0)