Skip to content

Commit 42c4136

Browse files
CopilotArgoZhang
andcommitted
Implemented fix for multiple dialog scrolling issue
Co-authored-by: ArgoZhang <[email protected]>
1 parent 0623c63 commit 42c4136

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
@page "/test-scroll-dialog"
2+
@using BootstrapBlazor.Server.Components.Components
3+
@inject DialogService DialogService
4+
5+
<PageTitle>Test Scroll Dialog</PageTitle>
6+
7+
<h1>Test Multiple Dialog Scrolling</h1>
8+
9+
<p>This page tests the multiple dialog scrolling functionality.</p>
10+
11+
<div class="mb-3">
12+
<Button Text="Open First Dialog" OnClick="@OpenFirstDialog" />
13+
</div>
14+
15+
@code {
16+
private async Task OpenFirstDialog()
17+
{
18+
await DialogService.Show(new DialogOption()
19+
{
20+
Title = "First Dialog - Large Content",
21+
IsScrolling = true,
22+
Size = Size.Large,
23+
BodyTemplate = builder =>
24+
{
25+
builder.OpenElement(0, "div");
26+
builder.AddAttribute(1, "style", "height: 800px; padding: 20px;");
27+
28+
builder.OpenElement(2, "h4");
29+
builder.AddContent(3, "First Dialog Content");
30+
builder.CloseElement();
31+
32+
builder.OpenElement(4, "p");
33+
builder.AddContent(5, "This is the first dialog with scrollable content. You should be able to scroll this content.");
34+
builder.CloseElement();
35+
36+
// Add lots of content to make it scrollable
37+
for (int i = 1; i <= 50; i++)
38+
{
39+
builder.OpenElement(6 + i * 3, "p");
40+
builder.AddContent(7 + i * 3, $"Line {i}: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
41+
builder.CloseElement();
42+
}
43+
44+
// Add button to open second dialog
45+
builder.OpenElement(200, "div");
46+
builder.AddAttribute(201, "class", "mt-4");
47+
builder.OpenComponent<Button>(202);
48+
builder.AddAttribute(203, "Text", "Open Second Dialog");
49+
builder.AddAttribute(204, "OnClick", Microsoft.AspNetCore.Components.EventCallback.Factory.Create(this, OpenSecondDialog));
50+
builder.CloseComponent();
51+
builder.CloseElement();
52+
53+
builder.CloseElement();
54+
}
55+
});
56+
}
57+
58+
private async Task OpenSecondDialog()
59+
{
60+
await DialogService.Show(new DialogOption()
61+
{
62+
Title = "Second Dialog - Also Scrollable",
63+
IsScrolling = true,
64+
Size = Size.Large,
65+
BodyTemplate = builder =>
66+
{
67+
builder.OpenElement(0, "div");
68+
builder.AddAttribute(1, "style", "height: 600px; padding: 20px;");
69+
70+
builder.OpenElement(2, "h4");
71+
builder.AddContent(3, "Second Dialog Content");
72+
builder.CloseElement();
73+
74+
builder.OpenElement(4, "p");
75+
builder.AddAttribute(5, "style", "color: red; font-weight: bold;");
76+
builder.AddContent(6, "THIS IS THE SECOND DIALOG - IT SHOULD BE SCROLLABLE TOO!");
77+
builder.CloseElement();
78+
79+
// Add lots of content to make it scrollable
80+
for (int i = 1; i <= 30; i++)
81+
{
82+
builder.OpenElement(7 + i * 3, "p");
83+
builder.AddContent(8 + i * 3, $"Second Dialog Line {i}: This content should be scrollable in the second dialog. The bug was that this second dialog couldn't scroll.");
84+
builder.CloseElement();
85+
}
86+
87+
// Add button to open third dialog
88+
builder.OpenElement(200, "div");
89+
builder.AddAttribute(201, "class", "mt-4");
90+
builder.OpenComponent<Button>(202);
91+
builder.AddAttribute(203, "Text", "Open Third Dialog");
92+
builder.AddAttribute(204, "OnClick", Microsoft.AspNetCore.Components.EventCallback.Factory.Create(this, OpenThirdDialog));
93+
builder.CloseComponent();
94+
builder.CloseElement();
95+
96+
builder.CloseElement();
97+
}
98+
});
99+
}
100+
101+
private async Task OpenThirdDialog()
102+
{
103+
await DialogService.Show(new DialogOption()
104+
{
105+
Title = "Third Dialog - Testing Deep Nesting",
106+
IsScrolling = true,
107+
Size = Size.Medium,
108+
BodyTemplate = builder =>
109+
{
110+
builder.OpenElement(0, "div");
111+
builder.AddAttribute(1, "style", "height: 400px; padding: 20px;");
112+
113+
builder.OpenElement(2, "h4");
114+
builder.AddContent(3, "Third Dialog Content");
115+
builder.CloseElement();
116+
117+
builder.OpenElement(4, "p");
118+
builder.AddAttribute(5, "style", "color: green; font-weight: bold;");
119+
builder.AddContent(6, "THIRD LEVEL DIALOG - SHOULD ALSO SCROLL!");
120+
builder.CloseElement();
121+
122+
// Add content to make it scrollable
123+
for (int i = 1; i <= 20; i++)
124+
{
125+
builder.OpenElement(7 + i * 2, "p");
126+
builder.AddContent(8 + i * 2, $"Third Dialog Line {i}: Deep nested scrolling test.");
127+
builder.CloseElement();
128+
}
129+
130+
builder.CloseElement();
131+
}
132+
});
133+
}
134+
}

src/BootstrapBlazor/Components/Modal/Modal.razor.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
.modal-multiple .modal-dialog {
8686
position: fixed;
8787
inset: 0;
88+
display: flex;
89+
align-items: center;
90+
justify-content: center;
91+
padding: var(--bs-modal-margin, 0.5rem);
8892

8993
&:last-child:before {
9094
content: "";
@@ -94,6 +98,19 @@
9498
opacity: 0.3;
9599
pointer-events: auto;
96100
}
101+
102+
// Ensure scrolling works for multiple dialogs by fixing the modal-content sizing
103+
.modal-content {
104+
max-height: calc(100vh - var(--bs-modal-margin, 0.5rem) * 2);
105+
overflow: hidden;
106+
display: flex;
107+
flex-direction: column;
108+
}
109+
110+
.modal-body {
111+
overflow-y: auto;
112+
flex: 1 1 auto;
113+
}
97114
}
98115

99116
.modal-multiple ~ .modal-backdrop {

0 commit comments

Comments
 (0)