Skip to content

UseModalClose

katanakit-js / useModalClose

function useModalClose(modalSelector, useRemoveDOM?): void;

Defined in: infrastructure/dom/dom.service.ts:490

Closes a modal by adding the “hidden” class or removing it from the DOM. Clicking outside the modal or calling this function will hide it.

Parameter Type Default value Description
modalSelector string undefined A CSS selector string for the modal element.
useRemoveDOM? boolean false If true, removes the modal from the DOM entirely. If false, only adds the “hidden” class (CSS display: none).

void

// Hide modal with CSS hidden class (keeps element in DOM)
useModalClose(".modal-overlay", false);
// Remove modal from DOM completely
useModalClose(".modal-overlay", true);