Fix BxSelect element not showing label correctly (#449)

This commit is contained in:
redphx 2024-07-19 06:54:00 +07:00
parent 2ecd995e47
commit 66123bc4ef
4 changed files with 27 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@ -183,14 +183,14 @@ export class ControllerShortcut {
$fragment.appendChild($option); $fragment.appendChild($option);
} }
$container.dataset.hasGamepad = hasGamepad.toString();
if (hasGamepad) { if (hasGamepad) {
$select.appendChild($fragment); $select.appendChild($fragment);
$select.selectedIndex = 0; $select.selectedIndex = 0;
$select.dispatchEvent(new Event('change')); $select.dispatchEvent(new Event('input'));
} }
$container.dataset.hasGamepad = hasGamepad.toString();
} }
static #switchProfile(profile: string) { static #switchProfile(profile: string) {
@ -205,7 +205,7 @@ export class ControllerShortcut {
const $select = ControllerShortcut.#$selectActions[button as GamepadKey]!; const $select = ControllerShortcut.#$selectActions[button as GamepadKey]!;
$select.value = actions[button] || ''; $select.value = actions[button] || '';
BxEvent.dispatch($select, 'change', { BxEvent.dispatch($select, 'input', {
ignoreOnChange: true, ignoreOnChange: true,
}); });
} }

View File

@ -324,6 +324,9 @@ export class StreamSettings {
(window as any).BX_EXPOSED.disableGamepadPolling = true; (window as any).BX_EXPOSED.disableGamepadPolling = true;
BxEvent.dispatch(window, BxEvent.XCLOUD_DIALOG_SHOWN); BxEvent.dispatch(window, BxEvent.XCLOUD_DIALOG_SHOWN);
// Update video's settings
onChangeVideoPlayerType();
} }
hide() { hide() {
@ -772,8 +775,5 @@ export class StreamSettings {
document.documentElement.appendChild($overlay); document.documentElement.appendChild($overlay);
document.documentElement.appendChild($container); document.documentElement.appendChild($container);
// Update video's settings
onChangeVideoPlayerType();
} }
} }

View File

@ -22,7 +22,6 @@ export class BxSelectElement {
}); });
const isMultiple = $select.multiple; const isMultiple = $select.multiple;
let visibleIndex = $select.selectedIndex;
let $checkBox: HTMLInputElement; let $checkBox: HTMLInputElement;
let $label: HTMLElement; let $label: HTMLElement;
@ -42,7 +41,7 @@ export class BxSelectElement {
}); });
$checkBox.addEventListener('input', e => { $checkBox.addEventListener('input', e => {
const $option = getOptionAtIndex(visibleIndex); const $option = getOptionAtIndex($select.selectedIndex);
$option && ($option.selected = (e.target as HTMLInputElement).checked); $option && ($option.selected = (e.target as HTMLInputElement).checked);
$select.dispatchEvent(new Event('input')); $select.dispatchEvent(new Event('input'));
@ -61,7 +60,7 @@ export class BxSelectElement {
const render = () => { const render = () => {
// console.log('options', this.options, 'selectedIndices', this.selectedIndices, 'selectedOptions', this.selectedOptions); // console.log('options', this.options, 'selectedIndices', this.selectedIndices, 'selectedOptions', this.selectedOptions);
visibleIndex = normalizeIndex(visibleIndex); const visibleIndex = normalizeIndex($select.selectedIndex);
const $option = getOptionAtIndex(visibleIndex); const $option = getOptionAtIndex(visibleIndex);
let content = ''; let content = '';
@ -108,11 +107,10 @@ export class BxSelectElement {
const onPrevNext = (e: Event) => { const onPrevNext = (e: Event) => {
const goNext = e.target === $btnNext; const goNext = e.target === $btnNext;
const currentIndex = visibleIndex; const currentIndex = $select.selectedIndex;
let newIndex = goNext ? currentIndex + 1 : currentIndex - 1; let newIndex = goNext ? currentIndex + 1 : currentIndex - 1;
newIndex = normalizeIndex(newIndex); newIndex = normalizeIndex(newIndex);
visibleIndex = newIndex;
if (!isMultiple && newIndex !== currentIndex) { if (!isMultiple && newIndex !== currentIndex) {
$select.selectedIndex = newIndex; $select.selectedIndex = newIndex;
} }