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

Why selected-item-changed is fired two time ? #259

Closed rokity closed 6 years ago

rokity commented 6 years ago

Watch this stupid example:

<paper-dropdown-menu id="object" label="Dinosaurs" on-selected-item-changed="change">
      <paper-listbox slot="dropdown-content" selected="{{selected}}">
          <slot></slot>
      </paper-listbox>
    </paper-dropdown-menu>
<script>
    class DropdownInput extends Polymer.Element {
      static get is() { return 'dropdown-input'; }   
      change()
        {   
             console.log('change');    
        }
          }
    window.customElements.define(DropdownInput.is, DropdownInput);
  </script>

Why selecte-item-changed is called two time?

madiyetov commented 6 years ago

paper-dropdown-menu listens for iron-select and iron-deselect events. When you click on an item paper-listbox fires firstly iron-deselect then iron-select. On deselect paper-dropdown-menu drops own selected-item property and then on select it resets that property for an item you've choosen.

It seems dropping isn't needed here. Possibly it's useful for multi selection when user can deselect an item. If it is we can add if condition this.contentElement.multi === false to prevent dropping.