-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Programmatic Confirmations / Modals #337
Comments
"headlessui" does not have multimodal support, when siblings it requires it to be parent and child, if placed global, closing the Confirm modal closes the others |
You can already achieve this with VueUse useConfirmDialog, here is an example: https://stackblitz.com/edit/github-tcbigg-wntk1z?file=app.vue |
Hi, Any update on this? Is this planned? The creation of UModal programmatically? Thanks |
This has been implemented in #1319. |
I don't fully get, how useModal/UModal would help me here. How would I return a value from the modal? I would like to have a programmatic method to show a yes/no dialog, e.g.
If this is possible with useModal, maybe it would be a good idea to add an example to the docs? Seems like a common use case... |
|
Many thanks! Would you mind showing what your |
<script lang="ts" setup>
import type { InputSize } from '#ui/types'
const props = defineProps({
title: {
type: String,
default: '',
},
message: {
type: String,
default: '',
},
inputResult: {
type: Object as PropType< {
type: string
placeholder: string
size: InputSize
value: string
} >,
required: false,
},
onConfirm: {
type: Function,
default: () => {},
},
onCancel: {
type: Function,
default: () => {},
},
loading: {
type: Boolean,
default: false,
},
icon: {
type: String,
default: 'i-carbon-question-answering',
},
})
function closeModal() {
props.onCancel()
}
const pending = ref(false)
const msj = ref('')
async function confirmOK() {
props.onConfirm(msj.value)
}
</script>
<template>
<UModal
id="modalConfirm"
:ui="{
wrapper: 'relative z-50',
inner: 'fixed inset-0 overflow-y-auto z-60',
}"
>
<div class="p-1">
<div class="border-b dark:border-gray-800">
{{ title }}
</div>
<div class="font-sans text-lg">
{{ message }}
</div>
<UInput
v-show="inputResult"
id="refInput" v-model="msj" :ui="{
wrapper: 'relative z-[80]',
}"
size="xl"
autofocus
:type="inputResult?.type"
:placeholder="inputResult?.placeholder"
/>
<div>
<div class="flex justify-center p-2 gap-x-2 items-center">
<UButton :loading="pending" icon="i-carbon-checkmark" color="primary" variant="solid" @click="confirmOK" @touchstart="confirmOK">
SI
</UButton>
Ò
<UButton icon="i-carbon-close" color="red" variant="solid" @click="closeModal" @touchstart="closeModal">
NO
</UButton>
</div>
</div>
</div>
</UModal>
</template>
` |
Got it, many thanks! Is there a way to handle the case if the modal is closed (without pressing yes or no) but e.g., pressing ESC? PS: Or disable closing on ESC and handle the keystroke manually... |
@some-user123 The modal emits 2 events related to the closing: |
Not sure if my strategy is ideal, but maybe sharing what I have so far might be useful in having something like this in the UI
Usage:
Component (this would go in app.vue similar to notifications):
Composable:
related to #285
The text was updated successfully, but these errors were encountered: