mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
Merge pull request #231 from IBM/fix-modal
fix(modal): prevent clicking inside inner modal from closing the modal
This commit is contained in:
commit
84f567ad7c
5 changed files with 23 additions and 12 deletions
|
@ -14,7 +14,9 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if story === undefined}
|
{#if story === undefined}
|
||||||
<ComposedModal {...$$props.composedModal}>
|
<ComposedModal {...$$props.composedModal} on:click={(e) => {
|
||||||
|
console.log(e.target)
|
||||||
|
}}>
|
||||||
<ModalHeader {...$$props.modalHeader} />
|
<ModalHeader {...$$props.modalHeader} />
|
||||||
<ModalBody
|
<ModalBody
|
||||||
{...$$props.modalBody}
|
{...$$props.modalBody}
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
|
|
||||||
let buttonRef = null;
|
let buttonRef = null;
|
||||||
let innerModal = null;
|
let innerModal = null;
|
||||||
|
let didClickInnerModal = false;
|
||||||
|
|
||||||
setContext("ComposedModal", {
|
setContext("ComposedModal", {
|
||||||
closeModal: () => {
|
closeModal: () => {
|
||||||
|
@ -102,10 +103,9 @@
|
||||||
class:bx--modal--danger={danger}
|
class:bx--modal--danger={danger}
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:click
|
on:click
|
||||||
on:click={({ target }) => {
|
on:click={() => {
|
||||||
if (!innerModal.contains(target)) {
|
if (!didClickInnerModal) open = false;
|
||||||
open = false;
|
didClickInnerModal = false;
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
|
@ -121,7 +121,10 @@
|
||||||
bind:this={innerModal}
|
bind:this={innerModal}
|
||||||
class:bx--modal-container={true}
|
class:bx--modal-container={true}
|
||||||
class="{size && `bx--modal-container--${size}`}
|
class="{size && `bx--modal-container--${size}`}
|
||||||
{containerClass}">
|
{containerClass}"
|
||||||
|
on:click={() => {
|
||||||
|
didClickInnerModal = true;
|
||||||
|
}}>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
<Modal
|
<Modal
|
||||||
{...$$props}
|
{...$$props}
|
||||||
bind:open
|
bind:open
|
||||||
|
on:click={(e) => {
|
||||||
|
console.log(e.target)
|
||||||
|
}}
|
||||||
on:click:button--secondary={() => {
|
on:click:button--secondary={() => {
|
||||||
console.log('click button secondary');
|
console.log('click button secondary');
|
||||||
open = false;
|
open = false;
|
||||||
|
|
|
@ -110,6 +110,7 @@
|
||||||
let buttonRef = null;
|
let buttonRef = null;
|
||||||
let innerModal = null;
|
let innerModal = null;
|
||||||
let opened = false;
|
let opened = false;
|
||||||
|
let didClickInnerModal = false;
|
||||||
|
|
||||||
function focus(element) {
|
function focus(element) {
|
||||||
const node =
|
const node =
|
||||||
|
@ -165,10 +166,9 @@
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:click
|
on:click
|
||||||
on:click={({ target }) => {
|
on:click={() => {
|
||||||
if (!innerModal.contains(target)) {
|
if (!didClickInnerModal) open = false;
|
||||||
open = false;
|
didClickInnerModal = false;
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
|
@ -179,7 +179,10 @@
|
||||||
aria-modal="true"
|
aria-modal="true"
|
||||||
aria-label={ariaLabel}
|
aria-label={ariaLabel}
|
||||||
class:bx--modal-container={true}
|
class:bx--modal-container={true}
|
||||||
class={size && `bx--modal-container--${size}`}>
|
class={size && `bx--modal-container--${size}`}
|
||||||
|
on:click={() => {
|
||||||
|
didClickInnerModal = true;
|
||||||
|
}}>
|
||||||
<div class:bx--modal-header={true}>
|
<div class:bx--modal-header={true}>
|
||||||
{#if passiveModal}
|
{#if passiveModal}
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -177,7 +177,7 @@
|
||||||
class:bx--tooltip--a11y={true}
|
class:bx--tooltip--a11y={true}
|
||||||
class="{tooltipPosition && `bx--tooltip--${tooltipPosition}`}
|
class="{tooltipPosition && `bx--tooltip--${tooltipPosition}`}
|
||||||
{tooltipAlignment && `bx--tooltip--align-${tooltipAlignment}`}"
|
{tooltipAlignment && `bx--tooltip--align-${tooltipAlignment}`}"
|
||||||
on:click|stopPropagation={() => {
|
on:click={() => {
|
||||||
type = type === 'password' ? 'text' : 'password';
|
type = type === 'password' ? 'text' : 'password';
|
||||||
}}>
|
}}>
|
||||||
<span class:bx--assistive-text={true}>
|
<span class:bx--assistive-text={true}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue