Skip to content

Commit a17239a

Browse files
committed
fix(player): watch menu button hint part changes
closes #1102
1 parent 9bfa26e commit a17239a

3 files changed

Lines changed: 28 additions & 12 deletions

File tree

packages/vidstack/mangle.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,5 +776,7 @@
776776
"_saveLang": "tn",
777777
"_selectTracks": "un",
778778
"_watchSwipeGesture": "xn",
779-
"_appendSource": "yn"
779+
"_appendSource": "yn",
780+
"_hintEl": "zn",
781+
"_watchHintEl": "An"
780782
}

packages/vidstack/src/components/provider/provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ export class MediaProvider extends Component<MediaProviderProps, MediaProviderSt
5959
const resize = new ResizeObserver(animationFrameThrottle(this._onResize.bind(this)));
6060
resize.observe(el);
6161

62-
const mutation = new MutationObserver(this._onMutation.bind(this));
63-
mutation.observe(el, { attributes: true, childList: true });
62+
const mutations = new MutationObserver(this._onMutation.bind(this));
63+
mutations.observe(el, { attributes: true, childList: true });
6464

6565
this._onResize();
6666
this._onMutation();
6767

6868
onDispose(() => {
6969
resize.disconnect();
70-
mutation.disconnect();
70+
mutations.disconnect();
7171
});
7272
}
7373

packages/vidstack/src/components/ui/menu/menu-button.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, effect, prop, useContext } from 'maverick.js';
1+
import { Component, effect, onDispose, prop, signal, useContext } from 'maverick.js';
22
import { DOMEvent } from 'maverick.js/std';
33

44
import { FocusVisibleController } from '../../../foundation/observers/focus-visible';
@@ -20,6 +20,7 @@ export class MenuButton extends Component<MenuButtonProps, {}, MenuButtonEvents>
2020
};
2121

2222
private _menu!: MenuContext;
23+
private _hintEl = signal<HTMLElement | null>(null);
2324

2425
@prop
2526
get expanded() {
@@ -42,13 +43,12 @@ export class MenuButton extends Component<MenuButtonProps, {}, MenuButtonEvents>
4243
}
4344

4445
protected override onConnect(el: HTMLElement) {
45-
const hint = Array.from(el.querySelectorAll('[data-part="hint"]')).pop();
46-
if (hint) {
47-
effect(() => {
48-
const text = this._menu._hint();
49-
if (text) hint.textContent = text;
50-
});
51-
}
46+
effect(this._watchHintEl.bind(this));
47+
48+
this._onMutation();
49+
const mutations = new MutationObserver(this._onMutation.bind(this));
50+
mutations.observe(el, { attributeFilter: ['data-part'], childList: true, subtree: true });
51+
onDispose(() => mutations.disconnect());
5252

5353
onPress(el, (trigger) => {
5454
this.dispatch('select', { trigger });
@@ -58,6 +58,20 @@ export class MenuButton extends Component<MenuButtonProps, {}, MenuButtonEvents>
5858
private _watchDisabled() {
5959
this._menu._disableMenuButton(this.$props.disabled());
6060
}
61+
62+
private _watchHintEl() {
63+
const el = this._hintEl();
64+
if (!el) return;
65+
effect(() => {
66+
const text = this._menu._hint();
67+
if (text) el.textContent = text;
68+
});
69+
}
70+
71+
private _onMutation() {
72+
const hintEl = this.el?.querySelector<HTMLElement>('[data-part="hint"]');
73+
this._hintEl.set(hintEl ?? null);
74+
}
6175
}
6276

6377
export interface MenuButtonProps {

0 commit comments

Comments
 (0)