mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(overflowmenu): Allow to keep menu open after clicking items
This commit is contained in:
parent
a1c7d9bd7c
commit
070a719150
2 changed files with 14 additions and 2 deletions
|
@ -55,6 +55,9 @@
|
||||||
/** Obtain a reference to the overflow menu element */
|
/** Obtain a reference to the overflow menu element */
|
||||||
export let menuRef = null;
|
export let menuRef = null;
|
||||||
|
|
||||||
|
/** Persist the open state when click the items */
|
||||||
|
export let persistentClickItems = true;
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createEventDispatcher,
|
createEventDispatcher,
|
||||||
getContext,
|
getContext,
|
||||||
|
@ -202,8 +205,11 @@
|
||||||
class:bx--overflow-menu--xl="{size === 'xl'}"
|
class:bx--overflow-menu--xl="{size === 'xl'}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:click
|
on:click
|
||||||
on:click="{({ target }) => {
|
on:click="{(e) => {
|
||||||
if (!(menuRef && menuRef.contains(target))) {
|
if (persistentClickItems) {
|
||||||
|
e.stopPropagation(); // this propagate to window.click to cause close
|
||||||
|
}
|
||||||
|
if (!(menuRef && menuRef.contains(e.target))) {
|
||||||
open = !open;
|
open = !open;
|
||||||
if (!open) dispatch('close');
|
if (!open) dispatch('close');
|
||||||
}
|
}
|
||||||
|
|
6
types/OverflowMenu/OverflowMenu.svelte.d.ts
vendored
6
types/OverflowMenu/OverflowMenu.svelte.d.ts
vendored
|
@ -34,6 +34,12 @@ export interface OverflowMenuProps extends RestProps {
|
||||||
*/
|
*/
|
||||||
flipped?: boolean;
|
flipped?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to keep menu open after clicking the items
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
persistentClickItems?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the menu options class
|
* Specify the menu options class
|
||||||
* @default undefined
|
* @default undefined
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue