Docs

Blog

Gallery

Resources

Learn

Components

API Reference

Onboarding

Library

/

Chakra

/

Overlay

/

Modal

A modal dialog is a window overlaid on either the primary window or another dialog window. Content behind a modal dialog is inert, meaning that users cannot interact with it.

class ModalState(rx.State):
    show: bool = False

    def change(self):
        self.show = not (self.show)


def modal_example():
    return rx.chakra.vstack(
        rx.chakra.button(
            "Confirm", on_click=ModalState.change
        ),
        rx.chakra.modal(
            rx.chakra.modal_overlay(
                rx.chakra.modal_content(
                    rx.chakra.modal_header("Confirm"),
                    rx.chakra.modal_body(
                        "Do you want to confirm example?"
                    ),
                    rx.chakra.modal_footer(
                        rx.chakra.button(
                            "Close",
                            on_click=ModalState.change,
                        )
                    ),
                )
            ),
            is_open=ModalState.show,
        ),
    )

The wrapper that provides context for its children.

PropTypeDescriptionValues
is_openbool

If true, the modal will be open.

allow_pinch_zoombool

Handle zoom/pinch gestures on iOS devices when scroll locking is enabled. Defaults to false.

auto_focusbool

If true, the modal will autofocus the first enabled and interactive element within the ModalContent

block_scroll_on_mountbool

If true, scrolling will be disabled on the body when the modal opens.

close_on_escbool

If true, the modal will close when the Esc key is pressed

close_on_overlay_clickbool

If true, the modal will close when the overlay is clicked

is_centeredbool

If true, the modal will be centered on screen.

lock_focus_across_framesbool

Enables aggressive focus capturing within iframes. - If true: keep focus in the lock, no matter where lock is active - If false: allows focus to move outside of iframe

motion_presetstr

The transition that should be used for the modal

preserve_scroll_bar_gapbool

If true, a padding-right will be applied to the body element that's equal to the width of the scrollbar. This can help prevent some unpleasant flickering effect and content adjustment when the modal opens

return_focus_on_closebool

If true, the modal will return focus to the element that triggered it when it closes.

sizeLiteral

"xs" | "sm" | "md" | "lg" | "xl" | "full"

use_inertbool

A11y: If true, the siblings of the modal will have aria-hidden set to true so that screen readers can only see the modal. This is commonly known as making the other elements inert

Event Triggers

TriggerDescription
on_close

The on_close event handler is called when the user closes a form. For example, it is called when the user clicks on a close button.

on_close_complete

The on_close_complete event handler is called when the user closes a form. For example, it is called when the user clicks on a close complete button.

on_esc

The on_esc event handler is called when the user presses the escape key. For example, it is called when the user presses the escape key.

on_overlay_click

The on_overlay_click event handler is called when the user clicks on an overlay. For example, it is called when the user clicks on a overlay button.

The dimmed overlay behind the modal dialog.

Props

No component specific props

Event Triggers

No component specific event triggers

The container for the modal dialog's content.

Props

No component specific props

Event Triggers

No component specific event triggers

The header that labels the modal dialog.

Props

No component specific props

Event Triggers

No component specific event triggers

The wrapper that houses the modal's main content.

Props

No component specific props

Event Triggers

No component specific event triggers

The footer that houses the modal events.

Props

No component specific props

Event Triggers

No component specific event triggers

Did you find this useful?

HomeGalleryChangelogIntroductionHosting