mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Switch source selection to same logic as SoundMode with using (#3136)
actual value as selected item instead of index. This avoids the bug with selected: https://github.com/PolymerElements/paper-dropdown-menu/issues/197 https://github.com/PolymerElements/paper-dropdown-menu/issues/114 Fixes: #3022 Side note: it actually mainly hides the issue. If we should allow a key, value setup with source being a key and the display value being a localized value it likely would return.
This commit is contained in:
parent
d8f21d99af
commit
f943393ade
@ -154,9 +154,13 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
label-float=""
|
label-float=""
|
||||||
label="[[localize('ui.card.media_player.source')]]"
|
label="[[localize('ui.card.media_player.source')]]"
|
||||||
>
|
>
|
||||||
<paper-listbox slot="dropdown-content" selected="{{sourceIndex}}">
|
<paper-listbox
|
||||||
|
slot="dropdown-content"
|
||||||
|
attr-for-selected="item-name"
|
||||||
|
selected="{{SourceInput}}"
|
||||||
|
>
|
||||||
<template is="dom-repeat" items="[[playerObj.sourceList]]">
|
<template is="dom-repeat" items="[[playerObj.sourceList]]">
|
||||||
<paper-item>[[item]]</paper-item>
|
<paper-item item-name$="[[item]]">[[item]]</paper-item>
|
||||||
</template>
|
</template>
|
||||||
</paper-listbox>
|
</paper-listbox>
|
||||||
</ha-paper-dropdown-menu>
|
</ha-paper-dropdown-menu>
|
||||||
@ -214,9 +218,9 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
observer: "playerObjChanged",
|
observer: "playerObjChanged",
|
||||||
},
|
},
|
||||||
|
|
||||||
sourceIndex: {
|
SourceInput: {
|
||||||
type: Number,
|
type: String,
|
||||||
value: 0,
|
value: "",
|
||||||
observer: "handleSourceChanged",
|
observer: "handleSourceChanged",
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -249,7 +253,7 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
|
|
||||||
playerObjChanged(newVal, oldVal) {
|
playerObjChanged(newVal, oldVal) {
|
||||||
if (newVal && newVal.sourceList !== undefined) {
|
if (newVal && newVal.sourceList !== undefined) {
|
||||||
this.sourceIndex = newVal.sourceList.indexOf(newVal.source);
|
this.SourceInput = newVal.source;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newVal && newVal.soundModeList !== undefined) {
|
if (newVal && newVal.soundModeList !== undefined) {
|
||||||
@ -342,26 +346,16 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
this.playerObj.nextTrack();
|
this.playerObj.nextTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSourceChanged(sourceIndex, sourceIndexOld) {
|
handleSourceChanged(newVal, oldVal) {
|
||||||
// Selected Option will transition to '' before transitioning to new value
|
// Selected Option will transition to '' before transitioning to new value
|
||||||
if (
|
if (
|
||||||
!this.playerObj ||
|
oldVal &&
|
||||||
!this.playerObj.supportsSelectSource ||
|
newVal &&
|
||||||
this.playerObj.sourceList === undefined ||
|
newVal !== this.playerObj.source &&
|
||||||
sourceIndex < 0 ||
|
this.playerObj.supportsSelectSource
|
||||||
sourceIndex >= this.playerObj.sourceList ||
|
|
||||||
sourceIndexOld === undefined
|
|
||||||
) {
|
) {
|
||||||
return;
|
this.playerObj.selectSource(newVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sourceInput = this.playerObj.sourceList[sourceIndex];
|
|
||||||
|
|
||||||
if (sourceInput === this.playerObj.source) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.playerObj.selectSource(sourceInput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSoundModeChanged(newVal, oldVal) {
|
handleSoundModeChanged(newVal, oldVal) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user