diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 0f7fb416b19..07e4f996049 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 7.8.10-beta01 + 7.8.10-beta02 diff --git a/src/BootstrapBlazor/Components/GoTop/GoTop.razor.cs b/src/BootstrapBlazor/Components/GoTop/GoTop.razor.cs index 04bd2ef74bc..8c8eb7ac2e2 100644 --- a/src/BootstrapBlazor/Components/GoTop/GoTop.razor.cs +++ b/src/BootstrapBlazor/Components/GoTop/GoTop.razor.cs @@ -53,6 +53,6 @@ protected override void OnParametersSet() /// /// /// - protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Target ?? ""); + protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Target); } diff --git a/src/BootstrapBlazor/Components/GoTop/GoTop.razor.js b/src/BootstrapBlazor/Components/GoTop/GoTop.razor.js index a554f9213d6..b0be2842474 100644 --- a/src/BootstrapBlazor/Components/GoTop/GoTop.razor.js +++ b/src/BootstrapBlazor/Components/GoTop/GoTop.razor.js @@ -1,6 +1,14 @@ import Data from "../../modules/data.js?v=$version" import EventHandler from "../../modules/event-handler.js?v=$version" +const getScrollElement = el => { + let ele = el + while (ele && ele.scrollHeight <= ele.clientHeight) { + ele = ele.parentNode + } + return ele || window +} + export function init(id, target) { const el = document.getElementById(id) if (el === null) { @@ -12,7 +20,8 @@ export function init(id, target) { go.tip = new bootstrap.Tooltip(el) EventHandler.on(el, 'click', e => { e.preventDefault(); - const element = document.querySelector(target) || window + + const element = (target && document.querySelector(target)) || getScrollElement(el) element.scrollTop = 0 go.tip.hide() })