Skip to content

Commit

Permalink
fix(modal): emit close event fires when modal content is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Sep 26, 2022
1 parent e9bd2bb commit 42cf87f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions lib/components/SModal.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
<script setup lang="ts">
import { ref } from 'vue'
export interface Props {
open: boolean
closable?: boolean
}
withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<Props>(), {
closable: true
})
defineEmits<{
const emit = defineEmits<{
(e: 'close'): void
}>()
const el = ref<any>(null)
function onClick(e: any) {
if (!props.closable) {
return
}
if (e.target === el.value) {
emit('close')
}
}
</script>

<template>
<Teleport to="#sefirot-modals">
<transition name="fade">
<div v-if="open" class="SModal" @click="closable && $emit('close')">
<div v-if="open" class="SModal" ref="el" @click="onClick">
<slot />
</div>
</transition>
Expand Down
4 changes: 2 additions & 2 deletions lib/components/SSheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ withDefaults(defineProps<Props>(), {
closable: true
})
defineEmits<{
const emit = defineEmits<{
(e: 'close'): void
}>()
</script>

<template>
<SMount class="SSheet" :class="[size]" @click.stop="() => {}">
<SMount class="SSheet" :class="[size]">
<button v-if="closable ?? true" class="close" @click="$emit('close')">
<SIcon :icon="IconX" class="icon" />
</button>
Expand Down

0 comments on commit 42cf87f

Please sign in to comment.