Skip to content

Commit

Permalink
fix(GoTop): should not throw exception when Target is null or empty (#…
Browse files Browse the repository at this point in the history
…1594)

* refactor: 更新 GoTop 组件

* refactor: 更新 GoTop 脚本

* chore: bump version 7.8.10-beta02
  • Loading branch information
ArgoZhang authored Jul 20, 2023
1 parent d78e9de commit 6ce6637
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
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>7.8.10-beta01</Version>
<Version>7.8.10-beta02</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/GoTop/GoTop.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ protected override void OnParametersSet()
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Target ?? "");
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Target);

}
11 changes: 10 additions & 1 deletion src/BootstrapBlazor/Components/GoTop/GoTop.razor.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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()
})
Expand Down

0 comments on commit 6ce6637

Please sign in to comment.