KTUIKTUI
KTUIKTUI
ComponentsDocsStudio

Getting Started

IntroductionInstallationApproachThemingJavaScriptDark modeRTLReferencesChangelog - v1.0.12Metronic TemplatePopular

Components

AccordionAvatarAlertBadgeBreadcrumbButtonCardCheckboxCollapseDatatableDatepickerSoonDismissDrawerDropdownImage InputInputUpdateKbdLinkModalPaginationProgressRadio GroupReparentScrollableScrollspyUpdateScrolltoSelectSeparatorSkeletonStepperStickySwitchTabsTextareaTheme SwitchToastNewTooltipToggleToggle GroupToggle PasswordTooltip
©2025 KtUI. All rights reserved.
A project by Keenthemes
Docs
Tailwind Dismiss

Tailwind Dismiss

Tailwind Dismiss component allows users to hide elements like alerts or notifications with a click.

Examples

Basic Usage

Dismiss the element with a smooth transition, ensuring it is removed from the DOM.

<div
  class="kt-alert"
  role="alert"
  aria-labelledby="alert_heading"
  aria-describedby="alert_message"
  id="alert"
>
  <div class="kt-alert-icon">
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      class="lucide lucide-triangle-alert size-6 text-destructive"
      aria-hidden="true"
    >
      <path
        d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"
      ></path>
      <path d="M12 9v4"></path>
      <path d="M12 17h.01"></path>
    </svg>
  </div>
  <div class="kt-alert-title flex items-center gap-1.5" id="alert_heading">
    <span class="font-semibold">Attention Required!</span>Please review the
    details to resolve the issue
  </div>
  <button
    class="kt-alert-close"
    data-kt-dismiss="#alert"
    aria-label="Close alert"
  >
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      class="lucide lucide-x"
      aria-hidden="true"
    >
      <path d="M18 6 6 18"></path>
      <path d="m6 6 12 12"></path>
    </svg>
  </button>
</div>

Hide Mode

Dismiss the element with a smooth transition, ensuring it is hidden with .hidden Tailwind Class.

<div class="space-y-2.5">
  <div
    class="kt-alert"
    role="alert"
    aria-labelledby="alert_heading"
    aria-describedby="alert_message"
    id="alert"
  >
    <div class="kt-alert-icon">
      <svg
        xmlns="http://www.w3.org/2000/svg"
        width="24"
        height="24"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        class="lucide lucide-info text-primary"
        aria-hidden="true"
      >
        <circle cx="12" cy="12" r="10"></circle>
        <path d="M12 16v-4"></path>
        <path d="M12 8h.01"></path>
      </svg>
    </div>
    <div class="kt-alert-content">
      <h2 class="kt-alert-title" id="alert_heading">Attention Required!</h2>
      <p class="kt-alert-description" id="alert_message">
        Please review the details to resolve the issue
      </p>
    </div>
    <div class="kt-alert-tooltip">
      <button
        class="kt-alert-close"
        data-kt-dismiss="#alert"
        data-kt-dismiss-mode="hide"
        aria-label="Close alert"
      >
        <svg
          xmlns="http://www.w3.org/2000/svg"
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          class="lucide lucide-x"
          aria-hidden="true"
        >
          <path d="M18 6 6 18"></path>
          <path d="m6 6 12 12"></path>
        </svg>
      </button>
    </div>
  </div>
  <button
    type="button"
    class="kt-btn hidden"
    id="alert_restore"
    aria-controls="alert"
    aria-expanded="false"
  >
    Display back
  </button>
</div>

Components API

Options

These data attributes allow you to set options for the dismiss component during auto initialization.

OptionTypeDefaultDescription
data-kt-collapse-hidden-classstring"hidden"Tailwind class to use for the hidden state of the dismissable elements.
data-kt-dismiss-interruptboolean"true"Prevents event propagation when the dismiss element is clicked.
data-kt-dismiss-modeenum"remove"By using "hide" mode, you can hide dismissed elements within the DOM structure, preserving their state for potential re-display later. This differs from the default behavior "remove" , which permanently removes them from the DOM.

Selectors

This table details the data attributes used by the dismiss component.

NameDescription
Data Attributes
data-kt-dismissUsed to auto-initialize KTDismiss instances on page load and provides a string value serving as an ID selector, "#content_id" for a collapsible element. Alternatively, you can remove it and perform initialization using JavaScript.

Methods

Use KTDismiss component's API methods to programmatically control its behavior.

MethodDescription
new KTDismiss(element, options)Creates an object instance of KTCollapse class for the given DOM element and configuration options.
dismiss()Executes the dismissal action on the target element.
getTargetElement()Retrieves the DOM element targeted by a specific KTDismiss instance.
getOption(name)Retrieves the value of a configuration option by name parameter from a KTDismiss instance.
getElement()Retrieves the DOM element linked to a specific KTDismiss instance.
on(eventName, handler)Allows attaching event listeners to the KTCollapse custom events using the eventName and eventId string parameters. These events enable programmatic interaction based on user actions or internal state changes of KTCollapse. The function returns string as a unique identifier for the registered listener, allowing you to remove it later if needed.
off(eventName, eventId)Removes an event listener for the eventName and eventId parameters attached with the on method.
dispose()Removes the KTDismiss instance from an element, including any associated data stored on the DOM element.
const dismisserEl = document.querySelector('#my_dismisser');
const dismiss = KTDismiss.getInstance(dismisserEl);
 
// Create a new instance on demand.
const newDismiss = new KTDismiss(dismisserEl, {
	interrupt: true,
	mode: 'hide'
});
 
dismiss.dismiss();

Utilities

Manage and interact with KTDismiss instances using these static methods of KTDismiss JavaScript class.

MethodDescription
init()Automatically initializes KTDismiss object for all elements with the data-kt-dismiss attribute on page load.
createInstances()Allows to create KTDismiss instances for all elements that have been dynamically added to the DOM but haven't been activated yet.
getInstance(element)Returns the KTDismiss object associated with the given DOM element element .
getOrCreateInstance(element)Returns the existing KTDismiss object for the provided DOM element element , or creates a new instance if none exists, then returns the same.
// Initialize all dismisses
KTDismiss.init()
 
// Initialzie pending dismisses
KTDismiss.createInstances();
 
// Get dismiss object
const dismisserEl = document.querySelector('#my_dismisser');
const dismiss = KTDismiss.getInstance(dismisserEl);

Events

KTDismiss custom events allows you to register callback functions(event listeners) that will be invoked automatically whenever specific custom events are triggered within the component.

EventDescription
dismissdismiss Triggered immediately before a dismissible element is hidden.
dismissedTriggered immediately after a dismissible element is hidden.
const dismisserEl = document.querySelector('#my_dismisser');
const dismiss = KTDismiss.getInstance(dismisserEl);
 
dismiss.on('dismiss', () => {
	detail.cancel = true;
	console.log('dismiss action canceled');
});
 
dismiss.on('dismissed', () => {
	console.log('dismissed event');
});
PreviouseDatepickerNextDrawer

On This Page

  • Examples
    • Basic Usage
    • Hide Mode
  • Components API
    • Options
    • Selectors
    • Methods
    • Utilities
    • Events