diff --git a/core/rfb.js b/core/rfb.js index ea3bf58a..084a457a 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -432,8 +432,8 @@ export default class RFB extends EventTargetMixin { } } - focus() { - this._canvas.focus(); + focus(options) { + this._canvas.focus(options); } blur() { @@ -609,7 +609,7 @@ export default class RFB extends EventTargetMixin { return; } - this.focus(); + this.focus({ preventScroll: true }); } _setDesktopName(name) { diff --git a/docs/API.md b/docs/API.md index aa5aea7a..066e8950 100644 --- a/docs/API.md +++ b/docs/API.md @@ -328,7 +328,14 @@ Keyboard events will be sent to the remote server after this point. ##### Syntax - RFB.focus( ); + RFB.focus( [options] ); + +###### Parameters + +**`options`** *Optional* + - A `object` providing options to control how the focus will be + performed. Please see [`HTMLElement.focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) + for available options. #### RFB.blur() diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 5f505818..f70bc14f 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -392,6 +392,13 @@ describe('Remote Frame Buffer Protocol Client', function () { client.focus(); expect(client._canvas.focus).to.have.been.calledOnce; }); + + it('should include focus options', function () { + client._canvas.focus = sinon.spy(); + client.focus({ foobar: 12, gazonk: true }); + expect(client._canvas.focus).to.have.been.calledOnce; + expect(client._canvas.focus).to.have.been.calledWith({ foobar: 12, gazonk: true}); + }); }); describe('#blur', function () {