|
51 | 51 | let delayTimeout: number;
|
52 | 52 | let referenceElement: HTMLButtonElement = $state(undefined);
|
53 | 53 | let dropdownElement: HTMLDivElement = $state(undefined);
|
54 |
| - let controlElement: HTMLElement = $state(undefined); |
| 54 | + let controlElement: HTMLButtonElement = $state(undefined); |
55 | 55 | let hovered: number = $state(-1);
|
56 | 56 |
|
57 | 57 | /** Function that allows changing the state of the menu from outside the component */
|
|
91 | 91 | onMount(() => {
|
92 | 92 | if (!control) return;
|
93 | 93 |
|
94 |
| - controlElement = element.children[0] as HTMLElement; |
| 94 | + controlElement = element.children[0] as HTMLButtonElement; |
| 95 | + referenceElement = controlElement; |
95 | 96 | controlElement.setAttribute('role', 'button');
|
96 | 97 | controlElement.setAttribute('aria-haspopup', 'menu');
|
97 | 98 | controlElement.setAttribute('aria-expanded', String(opened));
|
98 | 99 | controlElement.setAttribute('aria-controls', uuid);
|
99 | 100 | if (menuButtonLabel) controlElement.setAttribute('aria-label', menuButtonLabel);
|
100 | 101 |
|
101 | 102 | controlElement.addEventListener('click', (event) => {
|
102 |
| - event.stopPropagation(); |
103 |
| - toggleMenu(); |
| 103 | + toggleMenu(event); |
104 | 104 | });
|
105 | 105 | controlElement.addEventListener('mouseenter', () =>
|
106 | 106 | trigger === 'hover' ? handleOpen() : null
|
|
122 | 122 | onopen();
|
123 | 123 | };
|
124 | 124 |
|
125 |
| - const toggleMenu = () => { |
| 125 | + const toggleMenu = (event?: Event) => { |
| 126 | + event?.stopPropagation(); |
| 127 | +
|
126 | 128 | if (opened) return handleClose();
|
127 | 129 | return handleOpen();
|
128 | 130 | };
|
|
207 | 209 | [clickoutside, clickOutsideParams]
|
208 | 210 | ]}
|
209 | 211 | class={cx(classes.root, className)}
|
210 |
| - on:mouseleave={handleMouseLeave} |
211 |
| - on:mouseenter={handleMouseEnter} |
| 212 | + onmouseleave={handleMouseLeave} |
| 213 | + onmouseenter={handleMouseEnter} |
212 | 214 | {...rest}
|
213 | 215 | >
|
214 | 216 | {#if control}
|
|
222 | 224 | aria-controls={uuid}
|
223 | 225 | aria-label={menuButtonLabel}
|
224 | 226 | title={menuButtonLabel}
|
225 |
| - on:click!stopPropagation={toggleMenu} |
226 |
| - on:keydown={(event) => handleKeyDown(castKeyboardEvent(event))} |
227 |
| - on:mouseenter={() => (trigger === 'hover' ? handleOpen() : null)} |
| 227 | + onclick={toggleMenu} |
| 228 | + onkeydown={(event) => handleKeyDown(castKeyboardEvent(event))} |
| 229 | + onmouseenter={() => (trigger === 'hover' ? handleOpen() : null)} |
228 | 230 | />
|
229 | 231 | {/if}
|
230 | 232 | <PopperContainer {withinPortal}>
|
|
249 | 251 | class={cx(classes.body)}
|
250 | 252 | aria-orientation="vertical"
|
251 | 253 | {radius}
|
252 |
| - on:mouseleave={() => (hovered = -1)} |
| 254 | + onmouseleave={() => (hovered = -1)} |
253 | 255 | {shadow}
|
254 | 256 | >
|
255 | 257 | {@render children?.()}
|
|
0 commit comments