1- import { Component , effect , prop , useContext } from 'maverick.js' ;
1+ import { Component , effect , onDispose , prop , signal , useContext } from 'maverick.js' ;
22import { DOMEvent } from 'maverick.js/std' ;
33
44import { 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
6377export interface MenuButtonProps {
0 commit comments