Skip to content

Commit bca59c9

Browse files
committed
fix: defer keyboard activation to child controls
1 parent e0569f2 commit bca59c9

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/AjaxUploader.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class AjaxUploader extends Component<UploadProps> {
364364
? {}
365365
: {
366366
onClick: openFileDialogOnClick ? this.onClick : () => {},
367-
onKeyDown: openFileDialogOnClick ? this.onKeyDown : () => {},
367+
onKeyDown: openFileDialogOnClick && !hasControlInside ? this.onKeyDown : () => {},
368368
onMouseEnter,
369369
onMouseLeave,
370370
onDrop: this.onFileDrop,

‎tests/uploader.spec.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,25 @@ describe('uploader', () => {
13351335
expect(container.querySelector('span')!).not.toHaveAttribute('role', 'button');
13361336
});
13371337

1338+
it.each(['Enter', ' '])('Should leave %p activation to the child control', key => {
1339+
const { container } = render(
1340+
<Upload hasControlInside>
1341+
<button type="button">Upload</button>
1342+
</Upload>,
1343+
);
1344+
const input = container.querySelector('input')!;
1345+
const button = container.querySelector('button')!;
1346+
const clickSpy = jest.spyOn(input, 'click').mockImplementation(() => {});
1347+
1348+
expect(fireEvent.keyDown(button, { key })).toBe(true);
1349+
expect(clickSpy).not.toHaveBeenCalled();
1350+
1351+
fireEvent.click(button);
1352+
expect(clickSpy).toHaveBeenCalledTimes(1);
1353+
1354+
clickSpy.mockRestore();
1355+
});
1356+
13381357
it("Should not be focusable and doesn't have role=button when click upload is disabled", () => {
13391358
const { container } = render(<Upload openFileDialogOnClick={false} />);
13401359

0 commit comments

Comments
 (0)