2 Modal
Byron edited this page 2026-10-02 23:48:56 +02:00

Warning

Don't forget to include the modal.js file whenever you want to use modals:

<script src="@(Assets["_content/CleanUI/modal.js"])"></script>

Basic

<CleanButton ButtonType="@(CleanButtonType.Primary)" onclick="window.Modal.open('basic-modal')">
	Open modal
</CleanButton>

<CleanModal Id="basic-modal" Title="A simple modal!">
	<ChildContent>
		This is the modal's content.
	</ChildContent>
	
	<FooterContent>
		<CleanButton ButtonType="@(CleanButtonType.Primary)" onclick="window.Modal.close('basic-modal')">
			OK
		</CleanButton>
	</FooterContent>
</CleanModal>

Disallow closing

Important

The Closable property only removes the close button and prevents the modal from closing when clicking the background mask. Calling the window.Modal.close method will sill close the modal.

<CleanButton ButtonType="@(CleanButtonType.Primary)" onclick="window.Modal.open('unclosable-modal')">
	Open unclosable modal
</CleanButton>

<CleanModal Id="unclosable-modal" Closable="false">
	<ChildContent>
		This modal is not closable.
	</ChildContent>

	<FooterContent>
		<CleanButton ButtonType="@(CleanButtonType.Danger)" onclick="window.Modal.close('unclosable-modal')">
			Close anyway :)
		</CleanButton>
	</FooterContent>
</CleanModal>

Using IJsRuntime

Warning

Using the IJsRuntime requires the Interactive rendering mode.

A modal can also be opened and closed using the IJsRuntime.

private readonly IJsRuntime js;

public ValueTask OpenModalAsync() =>
	this.js.OpenModalAsync("MODAL-ID");

public ValueTask CloseModalAsync() =>
	this.js.CloseModalAsync("MODAL-ID");