Skip to content

Commit

Permalink
fix(Table): calc table height incorrect when invisible at first render (
Browse files Browse the repository at this point in the history
#3980)

* fix: 修复不可见表格高度计算不正确问题

* refactor: 使用动画帧 api

* chore: bump version 8.8.2-beta02
  • Loading branch information
ArgoZhang authored Aug 5, 2024
1 parent 3468812 commit e2c60b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.8.2-beta01</Version>
<Version>8.8.2-beta02</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
15 changes: 15 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ export function dispose(id) {
Data.remove(id)

if (table) {
if (table.loopCheckHeightHandler) {
cancelAnimationFrame(table.loopCheckHeightHandler);
}
if (table.thead) {
EventHandler.off(table.body, 'scroll')
}
Expand Down Expand Up @@ -243,13 +246,25 @@ const setColumnToolboxListener = table => {
}
}

const check = table => {
const el = table.el;
if (isVisible(el) === false) {
table.loopCheckHeightHandler = requestAnimationFrame(() => check(table));
}
else {
delete table.loopCheckHeightHandler;
setBodyHeight(table);
}
};

const setBodyHeight = table => {
const el = table.el
const children = [...el.children]
const search = children.find(i => i.classList.contains('table-search'))
table.search = search;

if (isVisible(el) === false) {
table.loopCheckHeightHandler = requestAnimationFrame(() => check(table));
return;
}

Expand Down

0 comments on commit e2c60b7

Please sign in to comment.