I am using paper-dropdown-menu in Polymer 2.x as shown below:
<paper-dropdown-menu label="Person" class="item">
<paper-listbox id="name" slot="dropdown-content" attr-for-selected="value" selected="{{selName}}" on-iron-select="nameSelected">
<paper-item value="John">John</paper-item>
<paper-item value="Bush">Bush</paper-item>
<paper-item value="Afridi">Afridi</paper-item>
</paper-listbox>
</paper-dropdown-menu>
When I select some item from above drop down menu, the drop down is populated based on the selected value as shown below:
<paper-dropdown-menu label="Balance" class="item">
<paper-listbox id="Balance" slot="dropdown-content" attr-for-selected="value" selected="{{selValue}}">
<template is="dom-repeat" items="[[data]]">
<paper-item value="{{item}}">{{item}}</paper-item>
</template>
</paper-listbox>
</paper-dropdown-menu>
Event Handler
nameSelected(event) {
var selectedItem = event.target.selectedItem.textContent;
this.data = [];
if (selectedItem === 'John') {
for (var i = 0; i < 20; i++) {
this.data.push(i);
}
} else {
for (var i = 20; i < 40; i++) {
this.data.push(i);
}
}
this.selValue = this.data[0];
}
When first time page loads, then first value (which is John) from Person drop down menu is pre-selected. Due to this, the first item in Balance drop down menu (which is zero) is also pre-selected. This is fine. The problem is that when I change selection in the Person drop down menu, then although Balance drop down menu is correctly populated but first value is not preselected.
Can you please guide me to fix this issue.