Skip to content

Headless Mode

Though the package comes with a default customizable UI, you can also use it in headless mode and provide your own UI. This way, you can still utilize the package's functionality without the default UI. You may use the HeadlessModal component to create your own UI. Please note that you are on your own when it comes to implementing this, as we cannot provide support for the unlimited possibilities of custom UIs.

HeadlessModal component

The Headless component provides the following props:

PropDescription
afterLeaveFunction to call after the modal has left the screen to remove it from the DOM
closeFunction to close the modal
configThe configuration passed to the modal
emitFunction to emit an event
getChildModalFunction to get first the child modal
getParentModalFunction to get the parent modal
idThe modal's unique ID
indexThe modal stack index
isOpenBoolean indicating if the modal is open
modalContextObject with all of the props in this table
onTopOfStackBoolean indicating if the modal is on top of the stack
reloadFunction to reload props
setOpenFunction to toggle the modal's open state

Here is an example of how to use the HeadlessModal component:

vue
<script setup>
import { HeadlessModal } from '@inertiaui/modal-vue'
import { ref } from 'vue'

const modal = ref(null)

function closeModal() {
    modal.value.close()
}
</script>

<template>
    <HeadlessModal
        ref="modalRef"
        v-slot="{
            afterLeave,
            close,
            config,
            emit,
            getChildModal,
            getParentModal,
            id,
            index,
            modalContext,
            onTopOfStack,
            isOpen,
            reload,
            setOpen,
        }"
    >
        <!-- Your custom modal here -->
    </HeadlessModal>
</template>
jsx
import { HeadlessModal } from '@inertiaui/modal-react'
import { useRef } from 'react'

export default function UserEdit({ ...props }) {
    const modalRef = useRef(null)

    function closeModal() {
        modalRef.current.close()
    }

    return (
        <HeadlessModal ref={modalRef} {...props}>
            {({ afterLeave,
                close,
                config,
                emit,
                getChildModal,
                getParentModal,
                id,
                index,
                modalContext,
                onTopOfStack,
                isOpen,
                reload,
                setOpen
            }) => (
                {/* Your custom modal here */ }
            )}
        </HeadlessModal>
    )
}