Modal
Modals are temporary pop-ups that take focus from the page or app and require people to interact with them. Unlike a dialog box (Dialog), a modal should be used for hosting lengthy content, such as privacy statements or license agreements, or for asking people to perform complex or multiple actions, such as changing settings.
Notes
There are two different modal components available for different purposes: BitModal is a basic, lightweight modal for simple pop-up content, while BitProModal is an advanced modal with extra features such as dragging, blocking, modeless, positioning, full-size and scroll handling. Pick the one that fits your use-case.
Usage
Basic
<BitButton OnClick="() => isOpenBasic = true">Open Modal</BitButton> <BitModal @bind-IsOpen="isOpenBasic"> <div style="padding:1rem;max-width:40rem"> In the beginning, there is silence a blank canvas yearning to be filled, a quiet space where creativity waits to awaken. These words are temporary, standing in place of ideas yet to come, a glimpse into the infinite possibilities that lie ahead. Think of this text as a bridge, connecting the empty spaces of now with the vibrant narratives of tomorrow. It whispers of the stories waiting to be told, of the thoughts yet to be shaped into meaning, and the emotions ready to resonate with every reader. <br /> In this space, potential reigns supreme. It is a moment suspended in time, where imagination dances freely and each word has the power to transform into something extraordinary. Here lies the start of something new-an opportunity to craft, inspire, and create. Whether it's a tale of adventure, a reflection of truth, or an idea that sparks change, these lines are yours to fill, to shape, and to make uniquely yours. The journey begins here, in this quiet moment where everything is possible. </div> </BitModal>@code { private bool isOpenBasic; }
Customizing content
<style> .modal-header { gap: 0.5rem; display: flex; font-size: 24px; font-weight: 600; align-items: center; padding: 12px 12px 14px 24px; border-top: 4px solid #0054C6; } .modal-header-text { flex-grow: 1; } .modal-body { max-width: 960px; line-height: 20px; overflow-y: hidden; padding: 0 24px 24px; } </style> <BitButton OnClick="() => isOpenCustomContent = true">Open Modal</BitButton> <BitModal @bind-IsOpen="isOpenCustomContent"> <div class="modal-header"> <span class="modal-header-text">Story title</span> <BitButton Variant="BitVariant.Text" OnClick="() => isOpenCustomContent = false" IconName="@BitIconName.ChromeClose" Title="Close" /> </div> <div class="modal-body"> Once upon a time, stories wove connections between people, a symphony of voices crafting shared dreams. Each word carried meaning, each pause brought understanding. Placeholder text reminds us of that moment when possibilities are limitless, waiting for content to emerge. The spaces here are open for growth, for ideas that change minds and spark emotions. This is where the journey begins your words will lead the way. <br /> Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning-a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life. <br /> In the beginning, there is silence a blank canvas yearning to be filled, a quiet space where creativity waits to awaken. These words are temporary, standing in place of ideas yet to come, a glimpse into the infinite possibilities that lie ahead. Think of this text as a bridge, connecting the empty spaces of now with the vibrant narratives of tomorrow. It whispers of the stories waiting to be told, of the thoughts yet to be shaped into meaning, and the emotions ready to resonate with every reader. <br /> In this space, potential reigns supreme. It is a moment suspended in time, where imagination dances freely and each word has the power to transform into something extraordinary. Here lies the start of something new-an opportunity to craft, inspire, and create. Whether it's a tale of adventure, a reflection of truth, or an idea that sparks change, these lines are yours to fill, to shape, and to make uniquely yours. The journey begins here, in this quiet moment where everything is possible. </div> </BitModal>@code { private bool isOpenCustomContent; }
Blocking
<style> .modal-header { gap: 0.5rem; display: flex; font-size: 24px; font-weight: 600; align-items: center; padding: 12px 12px 14px 24px; border-top: 4px solid #0054C6; } .modal-header-text { flex-grow: 1; } .modal-body { max-width: 960px; line-height: 20px; overflow-y: hidden; padding: 0 24px 24px; } </style> <BitButton OnClick="() => isOpenBlocking = true">Open blocking Modal</BitButton> <BitModal @bind-IsOpen="isOpenBlocking" Blocking> <div class="modal-header"> <span class="modal-header-text">Blocking modal</span> <BitButton Variant="BitVariant.Text" OnClick="() => isOpenBlocking = false" IconName="@BitIconName.ChromeClose" Title="Close" /> </div> <div class="modal-body"> Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning-a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life. </div> </BitModal>@code { private bool isOpenBlocking; }
Events
<style> .modal-header { gap: 0.5rem; display: flex; font-size: 24px; font-weight: 600; align-items: center; padding: 12px 12px 14px 24px; border-top: 4px solid #0054C6; } .modal-header-text { flex-grow: 1; } .modal-body { max-width: 960px; line-height: 20px; overflow-y: hidden; padding: 0 24px 24px; } </style> <BitButton OnClick="() => isEventsOpen = true">Open Modal</BitButton> <div>Dismissed? [@isDismissed]</div> <div>Overlay clicked? [@isOverlayClicked]</div> <BitModal @bind-IsOpen="isEventsOpen" OnDismiss="HandleOnDismiss" OnOverlayClick="HandleOnOverlayClick"> <div class="modal-header"> <span class="modal-header-text">Events modal</span> <BitButton Title="Close" Variant="BitVariant.Text" OnClick="() => isEventsOpen = false" IconName="@BitIconName.ChromeClose" /> </div> <div class="modal-body"> Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning-a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life. </div> </BitModal>@code { private bool isEventsOpen; private bool isDismissed; private bool isOverlayClicked; private async Task HandleOnDismiss() { isDismissed = true; await Task.Delay(3000); isDismissed = false; } private void HandleOnOverlayClick() { isOverlayClicked = true; _ = Task.Delay(2000).ContinueWith(_ => { isOverlayClicked = false; InvokeAsync(StateHasChanged); }); } }
Style & Class
<style> .modal-header { gap: 0.5rem; display: flex; font-size: 24px; font-weight: 600; align-items: center; padding: 12px 12px 14px 24px; border-top: 4px solid #0054C6; } .modal-header-text { flex-grow: 1; } .modal-body { max-width: 960px; line-height: 20px; overflow-y: hidden; padding: 0 24px 24px; } .custom-class { border: 0.5rem solid tomato; background-color: darkgoldenrod; } .custom-root { border: 0.25rem solid #0054C6; } .custom-overlay { background-color: #ffbd5a66; } .custom-content { margin: 1rem; box-shadow: 0 0 10rem purple; border-end-end-radius: 1rem; border-end-start-radius: 1rem; } </style> <BitButton OnClick="() => isOpenStyle = true">Open styled modal</BitButton> <BitButton OnClick="() => isOpenClass = true">Open classed modal</BitButton> <BitModal @bind-IsOpen="isOpenStyle" Style="box-shadow: inset 0px 0px 1.5rem 1.5rem palevioletred;"> <div class="modal-header"> <span class="modal-header-text">Styled modal</span> <BitButton Variant="BitVariant.Text" OnClick="() => isOpenStyle = false" IconName="@BitIconName.ChromeClose" Title="Close" /> </div> <div class="modal-body"> Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning-a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life. </div> </BitModal> <BitModal @bind-IsOpen="isOpenClass" Class="custom-class"> <div class="modal-header"> <span class="modal-header-text">Classed modal</span> <BitButton Variant="BitVariant.Text" OnClick="() => isOpenClass = false" IconName="@BitIconName.ChromeClose" Title="Close" /> </div> <div class="modal-body"> Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning-a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life. </div> </BitModal> <BitButton OnClick="() => isOpenStyles = true">Open modal styles</BitButton> <BitButton OnClick="() => isOpenClasses = true">Open modal classes</BitButton> <BitModal @bind-IsOpen="isOpenStyles" Styles="@(new() { Overlay = "background-color: #4776f433;", Content = "box-shadow: 0 0 1rem tomato;" })"> <div class="modal-header"> <span class="modal-header-text">Modal styles</span> <BitButton Variant="BitVariant.Text" OnClick="() => isOpenStyles = false" IconName="@BitIconName.ChromeClose" Title="Close" /> </div> <div class="modal-body"> Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning-a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life. </div> </BitModal> <BitModal @bind-IsOpen="isOpenClasses" Classes="@(new() { Root = "custom-root", Overlay = "custom-overlay", Content = "custom-content" })"> <div class="modal-header"> <span class="modal-header-text">Modal classes</span> <BitButton Variant="BitVariant.Text" OnClick="() => isOpenClasses = false" IconName="@BitIconName.ChromeClose" Title="Close" /> </div> <div class="modal-body"> Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning-a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life. </div> </BitModal>@code { private bool isOpenStyle; private bool isOpenClass; private bool isOpenStyles; private bool isOpenClasses; }
RTL
<style> .modal-header { gap: 0.5rem; display: flex; font-size: 24px; font-weight: 600; align-items: center; padding: 12px 12px 14px 24px; border-top: 4px solid #0054C6; } .modal-header-text { flex-grow: 1; } .modal-body { max-width: 960px; line-height: 20px; overflow-y: hidden; padding: 0 24px 24px; } </style> <BitButton Dir="BitDir.Rtl" OnClick="() => isOpenRtl = true">باز کردن مُدال</BitButton> <BitModal Dir="BitDir.Rtl" @bind-IsOpen="isOpenRtl"> <div class="modal-header"> <span class="modal-header-text">لورم ایپسوم</span> <BitButton Variant="BitVariant.Text" OnClick="() => isOpenRtl = false" IconName="@BitIconName.ChromeClose" Title="Close" /> </div> <div class="modal-body"> <p> لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است و برای شرایط فعلی تکنولوژی مورد نیاز و کاربردهای متنوع با هدف بهبود ابزارهای کاربردی می باشد. کتابهای زیادی در شصت و سه درصد گذشته، حال و آینده شناخت فراوان جامعه و متخصصان را می طلبد تا با نرم افزارها شناخت بیشتری را برای طراحان رایانه ای علی الخصوص طراحان خلاقی و فرهنگ پیشرو در زبان فارسی ایجاد کرد. در این صورت می توان امید داشت که تمام و دشواری موجود در ارائه راهکارها و شرایط سخت تایپ به پایان رسد وزمان مورد نیاز شامل حروفچینی دستاوردهای اصلی و جوابگوی سوالات پیوسته اهل دنیای موجود طراحی اساسا مورد استفاده قرار گیرد. </p> <p> لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است و برای شرایط فعلی تکنولوژی مورد نیاز و کاربردهای متنوع با هدف بهبود ابزارهای کاربردی می باشد. کتابهای زیادی در شصت و سه درصد گذشته، حال و آینده شناخت فراوان جامعه و متخصصان را می طلبد تا با نرم افزارها شناخت بیشتری را برای طراحان رایانه ای علی الخصوص طراحان خلاقی و فرهنگ پیشرو در زبان فارسی ایجاد کرد. در این صورت می توان امید داشت که تمام و دشواری موجود در ارائه راهکارها و شرایط سخت تایپ به پایان رسد وزمان مورد نیاز شامل حروفچینی دستاوردهای اصلی و جوابگوی سوالات پیوسته اهل دنیای موجود طراحی اساسا مورد استفاده قرار گیرد. </p> <p> لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است و برای شرایط فعلی تکنولوژی مورد نیاز و کاربردهای متنوع با هدف بهبود ابزارهای کاربردی می باشد. کتابهای زیادی در شصت و سه درصد گذشته، حال و آینده شناخت فراوان جامعه و متخصصان را می طلبد تا با نرم افزارها شناخت بیشتری را برای طراحان رایانه ای علی الخصوص طراحان خلاقی و فرهنگ پیشرو در زبان فارسی ایجاد کرد. در این صورت می توان امید داشت که تمام و دشواری موجود در ارائه راهکارها و شرایط سخت تایپ به پایان رسد وزمان مورد نیاز شامل حروفچینی دستاوردهای اصلی و جوابگوی سوالات پیوسته اهل دنیای موجود طراحی اساسا مورد استفاده قرار گیرد. </p> </div> </BitModal>@code { private bool isOpenRtl; }
API
BitModal parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Blocking | bool | false | When enabled, prevents the Modal from being light dismissed by clicking outside the Modal (on the overlay). |
| ChildContent | RenderFragment? | null | The content of Modal, It can be Any custom tag or a text. |
| Classes | BitModalClassStyles? | null | Custom CSS classes for different parts of the BitModal component. |
| FullHeight | bool | false | Makes the Modal height 100% of its parent container. |
| FullWidth | bool | false | Makes the Modal width 100% of its parent container. |
| IsAlert | bool? | null | Determines the ARIA role of the Modal (alertdialog/dialog). |
| IsOpen | bool | false | Whether the Modal is displayed. |
| OnDismiss | EventCallback<MouseEventArgs> | A callback function for when the Modal is dismissed. | |
| OnOverlayClick | EventCallback<MouseEventArgs> | A callback function for when somewhere on the overlay element of the Modal is clicked. | |
| Styles | BitModalClassStyles? | null | Custom CSS styles for different parts of the BitModal component. |
| SubtitleAriaId | string? | null | ARIA id for the subtitle of the Modal, if any. |
| TitleAriaId | string? | null | ARIA id for the title of the Modal, if any. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitModalClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitModal. |
| Overlay | string? | null | Custom CSS classes/styles for the overlay of the BitModal. |
| Content | string? | null | Custom CSS classes/styles for the content of the BitModal. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
You can give us your feedback through our GitHub repo by filing a new Issue or starting a new Discussion.
Or you can review / edit this page on GitHub.