Skip to content

feat(MaskService): add Selector parameter #5361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 14, 2025
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
7 changes: 6 additions & 1 deletion src/BootstrapBlazor/Components/Mask/Mask.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (!firstRender)
{
await InvokeVoidAsync("update", Id, new { Show = _options != null, _options?.ContainerId });
await InvokeVoidAsync("update", Id, new
{
Show = _options != null,
_options?.ContainerId,
_options?.Selector
});
}
}

Expand Down
30 changes: 17 additions & 13 deletions src/BootstrapBlazor/Components/Mask/Mask.razor.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
export function update(id, options) {
const mask = document.getElementById(id);
if (mask) {
const { show, containerId } = options;
const { show } = options;
const el = document.querySelector(`[data-bb-mask="${id}"]`);
if (containerId) {
const container = document.getElementById(containerId);
if (container) {
const position = container.style.getPropertyValue('position');
if (position === '' || position === 'static') {
container.style.setProperty('position', 'relative');
}

if (show) {
el.style.setProperty('--bb-mask-position', 'absolute');
container.appendChild(el);
}
const container = getContainerBySelector(options);
if (container) {
const position = container.style.getPropertyValue('position');
if (position === '' || position === 'static') {
container.style.setProperty('position', 'relative');
}
if (show) {
el.style.setProperty('--bb-mask-position', 'absolute');
container.appendChild(el);
}
}
else {
Expand All @@ -31,3 +28,10 @@
}
}
}

const getContainerBySelector = options => {
const selector = getContainerById(options.containerId) ?? options.selector;
return selector ? document.querySelector(selector) : null;
}

const getContainerById = id => id ? `#${id}` : null;
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Components/Mask/MaskOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public class MaskOption
/// 获得/设置 遮罩父容器 id 默认 null 未设置
/// </summary>
public string? ContainerId { get; set; }

/// <summary>
/// 获得/设置 遮罩父容器选择器 Selector 默认 null 未设置
/// </summary>
public string? Selector { get; set; }
}
3 changes: 2 additions & 1 deletion test/UnitTest/Services/MaskServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ await maskService.Show(new MaskOption()
Opacity = 0.5f,
ZIndex = 1050,
ChildContent = builder => builder.AddContent(0, "test-mask-content"),
ContainerId = "test-9527"
ContainerId = "test-9527",
Selector = "test-mask-selector"
});
});
});
Expand Down