Skip to content

Commit

Permalink
fix(overflow-menu): dispatch "close" event when clicking outside (#1546)
Browse files Browse the repository at this point in the history
Fixes #1541
  • Loading branch information
metonym committed Dec 8, 2022
1 parent ba62f45 commit 837716f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
16 changes: 8 additions & 8 deletions COMPONENT_INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -2615,14 +2615,14 @@ None.

### Events

| Event name | Type | Detail |
| :--------- | :--------- | :-------------------------------------------- |
| close | dispatched | <code>{ index: number; text: string; }</code> |
| click | forwarded | -- |
| mouseover | forwarded | -- |
| mouseenter | forwarded | -- |
| mouseleave | forwarded | -- |
| keydown | forwarded | -- |
| Event name | Type | Detail |
| :--------- | :--------- | :-------------------------------------------------------- |
| close | dispatched | <code>null &#124; { index: number; text: string; }</code> |
| click | forwarded | -- |
| mouseover | forwarded | -- |
| mouseenter | forwarded | -- |
| mouseleave | forwarded | -- |
| keydown | forwarded | -- |

## `OverflowMenuItem`

Expand Down
2 changes: 1 addition & 1 deletion docs/src/COMPONENT_API.json
Original file line number Diff line number Diff line change
Expand Up @@ -8063,7 +8063,7 @@
{
"type": "dispatched",
"name": "close",
"detail": "{ index: number; text: string; }"
"detail": "null | { index: number; text: string; }"
},
{ "type": "forwarded", "name": "click", "element": "button" },
{ "type": "forwarded", "name": "mouseover", "element": "button" },
Expand Down
5 changes: 4 additions & 1 deletion src/OverflowMenu/OverflowMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
/**
* @event {{ index: number; text: string; }} close
* @event {null | { index: number; text: string; }} close
*/
/**
Expand Down Expand Up @@ -205,6 +205,7 @@
on:click="{({ target }) => {
if (!(menuRef && menuRef.contains(target))) {
open = !open;
if (!open) dispatch('close');
}
}}"
on:mouseover
Expand All @@ -217,6 +218,7 @@
e.preventDefault();
} else if (e.key === 'Escape') {
e.stopPropagation();
dispatch('close');
open = false;
buttonRef.focus();
}
Expand All @@ -225,6 +227,7 @@
on:focusout="{(e) => {
if (open) {
if (!buttonRef.contains(e.relatedTarget)) {
dispatch('close');
open = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion types/OverflowMenu/OverflowMenu.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface OverflowMenuProps
export default class OverflowMenu extends SvelteComponentTyped<
OverflowMenuProps,
{
close: CustomEvent<{ index: number; text: string }>;
close: CustomEvent<null | { index: number; text: string }>;
click: WindowEventMap["click"];
mouseover: WindowEventMap["mouseover"];
mouseenter: WindowEventMap["mouseenter"];
Expand Down

0 comments on commit 837716f

Please sign in to comment.