PolymerElements / paper-dropdown-menu

A Material Design browser select element
https://www.webcomponents.org/element/PolymerElements/paper-dropdown-menu
61 stars 107 forks source link

paper-dropdown-menu-light collapses after deselection #190

Closed mgiuffrida closed 3 years ago

mgiuffrida commented 7 years ago

Fiddle: https://jsfiddle.net/mgiuffrida/ug56pybu/

After selecting a value, deselecting a value causes the dropdown menu button to collapse. Doesn't seem to matter whether it has a label or no-label-float set.

markus1978 commented 7 years ago

I had/have the same issue. Here is what I found: paper-dropdown-menu-light uses <div id="input" tabindex="-1">&nbsp;</div> to render the selected item label. If the selection is changed to no selection, this div's content is changed to "" and not to "&nbsp;". As a result the div's height is 0px and the whole component is displayed incorrectly.

If you replace paper-dropdown-menu-light's _valueChanged function with

_valueChanged: function() {
  // Only update if it's actually different.
  if (this.$.input && this.$.input.textContent !== this.value) {
    this.$.input.textContent = this.value;
    // insert &nbsp; if the value is empty string to enforce correct rendering
    if (this.value == "") {
      this.$.input.innerHTML = "&nbsp;";
    }
  }
  this._setHasContent(!!this.value);
},

this issue disappears.