Skip to content

Commit

Permalink
FileUploader: should be shown after press enter key on dxButton (T117…
Browse files Browse the repository at this point in the history
…8836) (#25803)

Signed-off-by: Alexander Bulychev <[email protected]>
Co-authored-by: Alexander Bulychev <[email protected]>
Co-authored-by: Anton Kuznetsov <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2023
1 parent 362cbd8 commit 7eaaae4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
8 changes: 4 additions & 4 deletions js/renovation/ui/__tests__/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,12 @@ describe('Button', () => {
originalEvent,
};
const button = new Button({ onClick });
const stub = jest.fn();

button.contentRef = { current: { click: stub } } as any;
button.keyDown(options);
expect(options.originalEvent.preventDefault).toHaveBeenCalled();
expect(onClick).toHaveBeenCalledTimes(1);
expect(onClick).toHaveBeenCalledWith({
event: options.originalEvent,
});
expect(stub).toHaveBeenCalledTimes(1);
});

it('should not simulate click by common keys down', () => {
Expand Down
6 changes: 5 additions & 1 deletion js/renovation/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,16 @@ export class Button extends JSXComponent(ButtonProps) {

if (keyName === 'space' || which === 'space' || keyName === 'enter' || which === 'enter') {
(originalEvent as Event).preventDefault();
this.onWidgetClick(originalEvent as Event);
this.emitClickEvent();
}

return undefined;
}

emitClickEvent(): void {
this.contentRef.current!.click();
}

get aria(): Record<string, string> {
const { text, icon } = this.props;

Expand Down
32 changes: 32 additions & 0 deletions testing/tests/DevExpress.ui.widgets.editors/fileUploader.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4338,3 +4338,35 @@ QUnit.module('readOnly option', moduleConfig, () => {

});

QUnit.module('dxButton integration', moduleConfig, () => {
QUnit.test('dialog should be shown after press enter key on dxButton (T1178836)', function(assert) {
if(devices.real().deviceType !== 'desktop') {
assert.ok(true, 'keyboard is not supported for not generic devices');
return;
}

const $customDialogTrigger = $('<div>').appendTo('#qunit-fixture');

$customDialogTrigger.dxButton({
text: 'button'
});

const instance = $('#fileuploader').dxFileUploader({
dialogTrigger: $customDialogTrigger,
visible: false
}).dxFileUploader('instance');
const spy = sinon.spy();

$(`.${FILEUPLOADER_INPUT_CLASS}`).on('click', spy);

instance.option({
uploadMode: 'useButtons',
});
assert.strictEqual(spy.callCount, 0, 'click on input not fired');

const keyboard = keyboardMock($customDialogTrigger);
keyboard.keyDown('enter');

assert.strictEqual(spy.callCount, 1, 'click on input fired');
});
});
18 changes: 18 additions & 0 deletions testing/tests/DevExpress.ui.widgets/button.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,24 @@ QUnit.module('Button', function() {
assert.equal(clickFired, 2, 'press space on button call click action');
});

QUnit.test('click event is fired on "enter" press', function(assert) {
const $element = $('#button').dxButton({
focusStateEnabled: true
});
const handler = sinon.spy();

$element.on('click', handler);

const keyboard = keyboardMock($element);

$element.trigger('focusin');
keyboard.keyDown('enter');
assert.strictEqual(handler.callCount, 1, 'press enter on button call click action');

keyboard.keyDown('space');
assert.strictEqual(handler.callCount, 2, 'press space on button call click action');
});

QUnit.test('arguments on key press', function(assert) {
const clickHandler = sinon.spy();

Expand Down

0 comments on commit 7eaaae4

Please sign in to comment.