Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(overflowmenu): Allow to keep menu open after clicking items #1788

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/OverflowMenu/OverflowMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
/** Obtain a reference to the overflow menu element */
export let menuRef = null;

/** Persist the open state when click the items */
export let persistentClickItems = true;

import {
createEventDispatcher,
getContext,
Expand Down Expand Up @@ -202,8 +205,11 @@
class:bx--overflow-menu--xl="{size === 'xl'}"
{...$$restProps}
on:click
on:click="{({ target }) => {
if (!(menuRef && menuRef.contains(target))) {
on:click="{(e) => {
if (persistentClickItems) {
e.stopPropagation(); // this propagate to window.click to cause close
}
if (!(menuRef && menuRef.contains(e.target))) {
open = !open;
if (!open) dispatch('close');
}
Expand Down
6 changes: 6 additions & 0 deletions types/OverflowMenu/OverflowMenu.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export interface OverflowMenuProps extends RestProps {
*/
flipped?: boolean;

/**
* Set to `true` to keep menu open after clicking the items
* @default false
*/
persistentClickItems?: boolean;

/**
* Specify the menu options class
* @default undefined
Expand Down