Skip to content
0

katanakit-js / useModalClose

Function: useModalClose() ​

ts
function useModalClose(modalSelector, useRemoveDOM?): void;

Defined in: src/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.

Parameters ​

ParameterTypeDefault valueDescription
modalSelectorstringundefinedA CSS selector string for the modal element.
useRemoveDOMbooleanfalseIf true, removes the modal from the DOM entirely. If false, only adds the "hidden" class (CSS display: none).

Returns ​

void

Example ​

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

// Remove modal from DOM completely
useModalClose(".modal-overlay", true);

Released under the MIT License.