Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/web-runtime/src/components/ModalWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const setCustomComponentRef = (id: Modal['id'], instance: unknown) => {
}

const onModalConfirm = async (modal: Modal, value?: unknown) => {
// custom components can confirm on their own (e.g. on Enter), which must not bypass the disabled button
if (modal.confirmDisabled) {
return
}

const customComponent = customComponentRefs.get(modal.id)

try {
Expand Down
10 changes: 10 additions & 0 deletions packages/web-runtime/tests/unit/components/ModalWrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ describe('ModalWrapper', () => {
expect(modalStore.updateModal).toHaveBeenCalled()
expect(modalStore.removeModal).toHaveBeenCalledWith(activeModal.id)
})
it('does nothing if confirm is disabled', async () => {
const activeModal = modal({ onConfirm: vi.fn(), confirmDisabled: true })
const { wrapper } = getShallowWrapper({ modals: [activeModal] })
const modalStore = useModals()

await (wrapper.vm as any).onModalConfirm(activeModal)

expect(activeModal.onConfirm).not.toHaveBeenCalled()
expect(modalStore.removeModal).not.toHaveBeenCalled()
})
it('does not remove the modal if the promise has not been resolved', async () => {
const activeModal = modal({ onConfirm: vi.fn().mockRejectedValue(new Error('')) })
const { wrapper } = getShallowWrapper({ modals: [activeModal] })
Expand Down
Loading