Skip to content

Modal

Display a modal dialog box, providing a title, content area, and action buttons.

Importing

To use the modal component, first you need to register the component inside the page. You can register the component manually by importing the register function:

ts
import { register } from "@tapsioss/web-components/modal";

register(); // Now the modal component is ready to use!
ts
import { registerModal } from "@tapsioss/web-components";

registerModal(); // Now the modal component is ready to use!

Also you can automatically register the component by importing it with the following approach:

ts
import "@tapsioss/web-components/modal/element";

TIP

If you want to use all the component in your app, you can call registerAll at the root of your project.

ts
import { registerAll } from "@tapsioss/web-components";

registerAll(); // All the components are now available

In the React package, you can easily add the component using the following code:

ts
import { Modal } from "@tapsioss/react-components";

Component Usage

html
<tapsi-modal></tapsi-modal>
tsx
<Modal />

Properties

NameAttribute NameDescriptionTypeDefault Value
headingheadingSets the title of the modal.string""
descriptiondescriptionSets the description text for the modal.string""
alignmentalignmentDetermines the alignment of the modal's content."start" | "center""start"
open-Determines whether the modal is open or not.booleanfalse

Methods

NameDescriptionParameters
showShow the modal.
hideHide the modal.

Slots

NameValueDescription
IMAGEimageThe slot for actionbar element.
ACTION_BARaction-barThe slot for actionbar element.

TIP

The value of slots are available for developer as JavaScript Variables:

ts
// Option 1
import { ModalSlots } from "@tapsioss/web-components";

// Option 2
import { Slots } from "@tapsioss/web-components/modal";
ts
// Option 1
import { ModalSlots } from "@tapsioss/react-components";

// Option 2
import { Slots } from "@tapsioss/react-components/Modal";

Events

NameDescriptionTypeBubblesCancelable
showFires when the modal should be visible.ShowEvent
hideFires when the modal should be hidden.HideEvent

TIP

Event details are available as JavaScript variables:

ts
// Option 1
import {
 ShowEvent,
 HideEvent
} from "@tapsioss/web-components/modal";

// Option 2
import {
 ModalShowEvent,
 ModalHideEvent
} from "@tapsioss/web-components";

You can have access to the event name using the type property:

ts
// Option 1
element.addEventListener(ShowEvent.type, handleShow);
element.addEventListener(HideEvent.type, handleHide);

// Option 2
element.addEventListener(ModalShowEvent.type, handleShow);
element.addEventListener(ModalHideEvent.type, handleHide);

Created with 🧡