Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>9.2.8-beta01</Version>
<Version>9.2.8-beta02</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/BootstrapBlazor/Components/Drawer/Drawer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
}
<div tabindex="-1" class="@DrawerClassString" style="@DrawerStyleString" @onclick:stopPropagation>
<div class="drawer-content">
<CascadingValue Value="Close" IsFixed=" true">
@ChildContent
<CascadingValue Name="BodyContext" Value="BodyContext" IsFixed="true">
<CascadingValue Value="Close" IsFixed=" true">
@ChildContent
</CascadingValue>
</CascadingValue>
</div>
@if (AllowResize)
Expand Down
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public partial class Drawer
[Parameter]
public Func<Task>? OnCloseAsync { get; set; }

/// <summary>
/// 获得/设置 抽屉内容相关数据 多用于传值
/// </summary>
[Parameter]
public object? BodyContext { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ private Dictionary<string, object> GetParameters(DrawerOption option)
{
parameters.Add(nameof(Drawer.OnClickBackdrop), option.OnClickBackdrop);
}
if (option.BodyContext != null)
{
parameters.Add(nameof(Drawer.BodyContext), option.BodyContext);
}
return parameters;
}

Expand Down
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Components/Drawer/DrawerOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public class DrawerOption
/// 获得/设置 关闭当前 Drawer 回调委托 默认 null
/// </summary>
public Func<Task>? OnCloseAsync { get; set; }

/// <summary>
/// 获得/设置 相关连数据,多用于传值使用
/// </summary>
public object? BodyContext { get; set; }
}
28 changes: 28 additions & 0 deletions test/UnitTest/Components/DrawerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ public void ChildContent_Ok()
Assert.NotNull(button);
}

[Fact]
public void BodyContext_Ok()
{
var cut = Context.RenderComponent<Drawer>(builder =>
{
builder.Add(a => a.BodyContext, "test-body-context");
builder.Add(a => a.ChildContent, s =>
{
s.OpenComponent<MockContent>(0);
s.CloseComponent();
});
});

var component = cut.FindComponent<MockContent>();
Assert.NotNull(component);

Assert.Equal("test-body-context", component.Instance.GetBodyContext());
}

[Fact]
public void ShowBackdrop_Ok()
{
Expand Down Expand Up @@ -141,4 +160,13 @@ public void Position_Ok()
});
cut.Contains("--bb-drawer-position: absolute;");
}

class MockContent : ComponentBase
{
[CascadingParameter(Name = "BodyContext")]
[NotNull]
private object? BodyContext { get; set; }

public string? GetBodyContext() => BodyContext.ToString();
}
}
3 changes: 2 additions & 1 deletion test/UnitTest/Services/DrawerServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public async Task Show_Ok()
OnClickBackdrop = () => Task.CompletedTask,
OnCloseAsync = () => Task.CompletedTask,
Placement = Placement.Bottom,
ShowBackdrop = true
ShowBackdrop = true,
BodyContext = "test-body-context"
};
var service = Context.Services.GetRequiredService<DrawerService>();
var cut = Context.RenderComponent<BootstrapBlazorRoot>();
Expand Down
Loading