Skip to content

Commit

Permalink
Assign menu and set forwardHostProps with observer
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-fix committed Aug 27, 2018
1 parent 1a138f4 commit 6132f7a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/vaadin-dropdown-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@
ready() {
super.ready();

this._overlayElement = this.shadowRoot.querySelector('vaadin-dropdown-menu-overlay');
this._valueElement = this.shadowRoot.querySelector('[part="value"]');
this._toggleElement = this.shadowRoot.querySelector('[part="toggle-button"]');
this._nativeInput = this.focusElement.shadowRoot.querySelector('input');
Expand All @@ -335,8 +334,17 @@
this.focusElement.addEventListener('click', e => this.opened = !this.readonly);
this.focusElement.addEventListener('keydown', e => this._onKeyDown(e));

const template = this.querySelector('template');
this._observer = new Polymer.FlattenedNodesObserver(this, info => this._setTemplateFromNodes(info.addedNodes));
this._observer.flush();
}

_setTemplateFromNodes(nodes) {
const template = Array.from(nodes).filter(node => node.localName && node.localName === 'template')[0] || this._contentTemplate;
this._overlayElement.template = this._contentTemplate = template;
this._setForwardHostProps();
}

_setForwardHostProps() {
if (this._overlayElement.content) {
const origForwardHostProp = this._overlayElement._instance && this._overlayElement._instance.forwardHostProp;

Expand Down Expand Up @@ -586,6 +594,13 @@
validate() {
return !(this.invalid = !(this.disabled || !this.required || this.value));
}

get _overlayElement() {
// TODO(yuriy): Ready and connected callbacks are called after property changes observers
// when content is rendererd with helper directive functions in lit-html, like repeat.
// Find a way to test it properly with other frameworks.
return this._savedOverlayElement || (this._savedOverlayElement = this.shadowRoot.querySelector('vaadin-dropdown-menu-overlay'));
}
}

customElements.define(DropdownMenuElement.is, DropdownMenuElement);
Expand Down

0 comments on commit 6132f7a

Please sign in to comment.