mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 03:26:36 +00:00
feat(ComposedModal): forward keydown event and add shouldSubmitOnEnter
This commit is contained in:
parent
720ef778f2
commit
08076fbefd
1 changed files with 13 additions and 0 deletions
|
@ -18,6 +18,9 @@
|
|||
/** Set to `true` to prevent the modal from closing when clicking outside */
|
||||
export let preventCloseOnClickOutside = false;
|
||||
|
||||
/** Set to `true` for the primary button to be triggered when pressing "Enter" */
|
||||
export let shouldSubmitOnEnter = true;
|
||||
|
||||
/** Specify a class for the inner modal */
|
||||
export let containerClass = "";
|
||||
|
||||
|
@ -103,6 +106,16 @@
|
|||
class:is-visible="{open}"
|
||||
class:bx--modal--danger="{danger}"
|
||||
{...$$restProps}
|
||||
on:keydown
|
||||
on:keydown="{({ key }) => {
|
||||
if (open) {
|
||||
if (key === 'Escape') {
|
||||
open = false;
|
||||
} else if (shouldSubmitOnEnter && key === 'Enter') {
|
||||
dispatch('submit');
|
||||
}
|
||||
}
|
||||
}}"
|
||||
on:click
|
||||
on:click="{() => {
|
||||
if (!didClickInnerModal && !preventCloseOnClickOutside) open = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue