mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
feat(ui-shell): add preventCloseOnClickOutside
to HeaderAction
(#1625)
Closes #1624
This commit is contained in:
parent
9b3f014a0b
commit
ea9b261b60
4 changed files with 36 additions and 9 deletions
|
@ -1601,14 +1601,15 @@ None.
|
||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
|
||||||
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
|
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
|
||||||
| :--------- | :------- | :--------------- | :------- | ----------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------- |
|
| :------------------------- | :------- | :--------------- | :------- | ----------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------- |
|
||||||
| ref | No | <code>let</code> | Yes | <code>null | HTMLButtonElement</code> | <code>null</code> | Obtain a reference to the button HTML element |
|
| ref | No | <code>let</code> | Yes | <code>null | HTMLButtonElement</code> | <code>null</code> | Obtain a reference to the button HTML element |
|
||||||
| isOpen | No | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the panel |
|
| isOpen | No | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the panel |
|
||||||
| icon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is closed.<br />Defaults to `<Switcher size={20} />` |
|
| icon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is closed.<br />Defaults to `<Switcher size={20} />` |
|
||||||
| closeIcon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is open.<br />Defaults to `<Close size={20} />` |
|
| closeIcon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is open.<br />Defaults to `<Close size={20} />` |
|
||||||
| text | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify the text<br />Alternatively, use the named slot "text" (e.g., <div slot="text">...</div>) |
|
| text | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify the text<br />Alternatively, use the named slot "text" (e.g., <div slot="text">...</div>) |
|
||||||
| transition | No | <code>let</code> | No | <code>false | import("svelte/transition").SlideParams</code> | <code>{ duration: 200 }</code> | Customize the panel transition (i.e., `transition:slide`).<br />Set to `false` to disable the transition |
|
| transition | No | <code>let</code> | No | <code>false | import("svelte/transition").SlideParams</code> | <code>{ duration: 200 }</code> | Customize the panel transition (i.e., `transition:slide`).<br />Set to `false` to disable the transition |
|
||||||
|
| preventCloseOnClickOutside | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to prevent the panel from closing when clicking outside |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
|
|
@ -4923,6 +4923,18 @@
|
||||||
"isRequired": false,
|
"isRequired": false,
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "preventCloseOnClickOutside",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Set to `true` to prevent the panel from closing when clicking outside",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": "false",
|
||||||
|
"isFunction": false,
|
||||||
|
"isFunctionDeclaration": false,
|
||||||
|
"isRequired": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"moduleExports": [],
|
"moduleExports": [],
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
*/
|
*/
|
||||||
export let transition = { duration: 200 };
|
export let transition = { duration: 200 };
|
||||||
|
|
||||||
|
/** Set to `true` to prevent the panel from closing when clicking outside */
|
||||||
|
export let preventCloseOnClickOutside = false;
|
||||||
|
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import { slide } from "svelte/transition";
|
import { slide } from "svelte/transition";
|
||||||
import Close from "../icons/Close.svelte";
|
import Close from "../icons/Close.svelte";
|
||||||
|
@ -50,7 +53,12 @@
|
||||||
|
|
||||||
<svelte:window
|
<svelte:window
|
||||||
on:click="{({ target }) => {
|
on:click="{({ target }) => {
|
||||||
if (isOpen && !ref.contains(target) && !refPanel.contains(target)) {
|
if (
|
||||||
|
isOpen &&
|
||||||
|
!ref.contains(target) &&
|
||||||
|
!refPanel.contains(target) &&
|
||||||
|
!preventCloseOnClickOutside
|
||||||
|
) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
}
|
}
|
||||||
|
|
6
types/UIShell/HeaderAction.svelte.d.ts
vendored
6
types/UIShell/HeaderAction.svelte.d.ts
vendored
|
@ -43,6 +43,12 @@ export interface HeaderActionProps
|
||||||
*/
|
*/
|
||||||
transition?: false | import("svelte/transition").SlideParams;
|
transition?: false | import("svelte/transition").SlideParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to prevent the panel from closing when clicking outside
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
preventCloseOnClickOutside?: boolean;
|
||||||
|
|
||||||
[key: `data-${string}`]: any;
|
[key: `data-${string}`]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue