Skip to content

Commit

Permalink
feat: add missing focus method to message-input (#7364)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Apr 29, 2024
1 parent 1c2f65e commit 27b8b91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/message-input/src/vaadin-message-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ class MessageInput extends ElementMixin(ThemableMixin(ControllerMixin(PolymerEle
this.addController(this._tooltipController);
}

focus() {
if (this._textArea) {
this._textArea.focus();
}
}

/** @private */
__buttonPropsChanged(button, disabled, i18n) {
if (button) {
Expand Down
13 changes: 13 additions & 0 deletions packages/message-input/test/message-input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,17 @@ describe('message-input', () => {
expect(messageInput.getAttribute('disabled')).to.exist;
});
});

describe('focus', () => {
it('should focus the text-area when calling focus()', () => {
const spy = sinon.spy(textArea, 'focus');
messageInput.focus();
expect(spy).to.be.calledOnce;
});

it('should not throw on focus when not attached to the DOM', () => {
const element = document.createElement('vaadin-message-input');
expect(() => element.focus()).not.to.throw(Error);
});
});
});

0 comments on commit 27b8b91

Please sign in to comment.