Skip to content

Commit 56ef57c

Browse files
authored
refactor(ModalDialog): update javascript check modal first shown (#4676)
* fix: 增加调整位置前检查 * chore: bump version 9.0.1-beta02 * refactor: 精简代码
1 parent 9a09c24 commit 56ef57c

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.0.0-beta03</Version>
4+
<Version>9.0.1-beta02</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,27 @@ export function init(id) {
121121
}
122122

123123
if (el.classList.contains('is-draggable-center')) {
124-
const width = el.offsetWidth / 2;
125-
const height = el.offsetHeight / 2;
126-
127-
el.style.setProperty("margin-left", `calc(50vw - ${width}px)`);
128-
el.style.setProperty("margin-top", `calc(50vh - ${height}px)`);
129-
el.classList.remove('is-draggable-center');
124+
const check = () => {
125+
if (el.offsetWidth > 0) {
126+
update(el);
127+
}
128+
else {
129+
requestAnimationFrame(check);
130+
}
131+
}
132+
requestAnimationFrame(check);
130133
}
131134
}
132135

136+
const update = el => {
137+
const width = el.offsetWidth / 2;
138+
const height = el.offsetHeight / 2;
139+
140+
el.style.setProperty("margin-left", `calc(50vw - ${width}px)`);
141+
el.style.setProperty("margin-top", `calc(50vh - ${height}px)`);
142+
el.classList.remove('is-draggable-center');
143+
}
144+
133145
export function dispose(id) {
134146
const dialog = Data.get(id)
135147
Data.remove(id)

0 commit comments

Comments
 (0)