frutjam logo
2.6.0-beta.0

Modal

To create a modal, we use the <dialog> element, which is natively supported in most modern browsers. For more information, visit MDN.

Dialog modal

Add a unique id to the <dialog id="myModal"> HTML element, then use that id in JavaScript to call myModal.showModal() to open the modal and myModal.close() to close the modal.

html

Close modal when click outside

The .modal-backdrop provides a clickable background that closes the modal when clicked outside the modal content.

html

Modal Slide Animations

Smoothly slide in and out from the top, bottom, start (left in LTR, right in RTL), or end (right in LTR, left in RTL) with the following directional utility classes: modal-slide-top, modal-slide-bottom, modal-slide-start, and modal-slide-end in the modal component. These animations improve the user experience through the use of dynamic transitions based on modal position.

Modal slide from start (Horizontal)

Add the modal-slide-start utility to slide the modal horizontally from the start side; in left-to-right (LTR) layouts, it appears from the left, and in right-to-left (RTL) layouts, from the right.

html

Modal slide from end (Horizontal)

Add the modal-slide-end utility in modal component to slide the modal horizontally from the end side; in left-to-right (LTR) layouts, it appears from the right, and in right-to-left (RTL) layouts, from the left.

html

Slide from Bottom (Vertical): modal-slide-up

Direction: Slides in vertically from the bottom

html

Slide from Top (Vertical)

Add the modal-slide-down utility in the modal component to slide in vertically from the top.

html

Example usage of sliding animation modal for notification

html

Modal placements

The modal component is by default positioned in the center of the screen, but it can be placed depending upon the use case using utility classes such as modal-x-{position} and modal-y-{position}, where {position} is start, center, or end. Placement is designed with RTL and LTR compatibility in mind, making the modal adaptable to different language directions and layouts.

Use modal-x-{position} for horizontal placement and modal-y-{position} for vertical placement, where {position} can be start, center, or end. These classes are applied to the modal component.

Top left modal placement

html

Top center modal placement

html

Top right modal placement

html

Center left modal placement

html

Center right modal placement

html

Bottom left modal placement

html

Bottom center modal placement

html

Bottom right modal placement

html

Responsive positioning of modal for desktop and mobile screens

Depending on your use case, you can position the modal anywhere on desktop or mobile—for example, desktop center and mobile top center.

html

Modal positioning based on language direction

Place the modal wherever on the screen depending on the language direction (LTR or RTL).

Right-aligned and vertically centered in LTR and RTL

html

Place the modal based on screen size and language direction.

html