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

This commit is contained in:
pwwang 2023-07-27 14:32:38 -07:00 committed by GitHub
commit 070a719150
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -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,
@ -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');
}

View file

@ -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