Skip to content

Commit 91eebc2

Browse files
authored
refactor(LayoutSplitebar): Enhanced javascript handle sidebar width is not set (#5512)
* refactor: 更新变量类型 * refactor: 删除重复组件 * refactor: 更新脚本逻辑 * refactor: 优化逻辑
1 parent 27f8299 commit 91eebc2

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet.razor

-6
This file was deleted.

src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet.razor.cs

-8
This file was deleted.

src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet.razor.css

-1
This file was deleted.

src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.razor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace BootstrapBlazor.Server.Components.Samples.Tutorials;
88
/// <summary>
99
/// Online sheet sample code
1010
/// </summary>
11-
public partial class OnlineSheet : ComponentBase, IDisposable
11+
public partial class OnlineSheet : IDisposable
1212
{
1313
[Inject, NotNull]
1414
private IWebHostEnvironment? WebHost { get; set; }

src/BootstrapBlazor/Components/Layout/LayoutSplitebar.razor.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ export function init(id) {
2020
let width = 0;
2121
Drag.drag(bar,
2222
e => {
23-
section.classList.add('drag')
24-
width = parseInt(getComputedStyle(section).getPropertyValue('--bb-layout-sidebar-width'))
25-
originX = e.clientX || e.touches[0].clientX
23+
section.classList.add('drag');
24+
const widthString = getComputedStyle(section).getPropertyValue('--bb-layout-sidebar-width');
25+
if (widthString === '') {
26+
section.style.setProperty('--bb-layout-sidebar-width', '0');
27+
widthString = '0';
28+
}
29+
width = parseInt(widthString);
30+
originX = e.clientX || e.touches[0].clientX;
2631
},
2732
e => {
2833
const eventX = e.clientX || (e.touches.length > 0 && e.touches[0].clientX)
2934
const moveX = eventX - originX
30-
const newWidth = width + moveX
35+
let newWidth = width + moveX
3136
if (min > -1 && newWidth < min) {
3237
newWidth = min
3338
}

0 commit comments

Comments
 (0)