Skip to content

Commit

Permalink
Merge pull request #131 from vaadin/fix/data-binding
Browse files Browse the repository at this point in the history
Fix data-binding in selected item
  • Loading branch information
tomivirkki committed Jun 27, 2018
2 parents 635c9fd + 134352e commit 071916d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/vaadin-dropdown-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@
const template = this.querySelector('template');
this._overlayElement.template = template;
if (this._overlayElement.content) {
const origForwardHostProp = this._overlayElement._instance && this._overlayElement._instance.forwardHostProp;

this._overlayElement._instance.forwardHostProp = (...args) => {
origForwardHostProp.apply(this._overlayElement._instance, args);
setTimeout(() => {
this._updateValueSlot();
});
};

this._menuElement = Array.from(this._overlayElement.content.children).filter(element => element.localName !== 'style')[0];

if (this._menuElement) {
Expand Down
10 changes: 10 additions & 0 deletions test/dropdown-menu-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@
expect(menu.items[0].textContent.trim()).to.equal('foo');
});

it('dropdown-menu should update selected item on host property changes', done => {
container.message = 'foo';
menu.selected = 0;
container.message = 'bar';
setTimeout(() => {
expect(dropdown._inputElement.querySelector('mock-item').textContent.trim()).to.equal('bar');
done();
});
});

it('dropdown-menu should support two-way data binding', () => {
const input = menu.items[1].querySelector('input');
input.value = 'bar';
Expand Down

0 comments on commit 071916d

Please sign in to comment.