Skip to content
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

🆕 feat(ExpansionPanel): support for lazy loading the DOM of content #428

Merged
merged 2 commits into from
Jun 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public partial class BExpansionPanel : BGroupItem<BExpansionPanels>
{
public BExpansionPanel() : base(GroupType.ExpansionPanels)
public BExpansionPanel() : base(GroupType.ExpansionPanels, true)
{
}

Expand All @@ -15,6 +15,8 @@ public BExpansionPanel() : base(GroupType.ExpansionPanels)

public bool IsReadonly => ItemGroup != null && (ItemGroup.Readonly || Readonly);

public bool Booted => IsBooted;

public async Task Toggle()
{
await ToggleAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@namespace BlazorComponent
@inherits BDomComponentBase

<ExpandTransition>
<ShowTransitionElement Value="ExpansionPanel?.InternalIsActive is true" class="@CssProvider.GetClass()" style="@CssProvider.GetStyle()">
<div class="@CssProvider.GetClass("wrap")">
@ChildContent
</div>
</ShowTransitionElement>
</ExpandTransition>

@if (_isBooted || Eager)
{
<ExpandTransition>
<ShowTransitionElement Value="_isActive" class="@CssProvider.GetClass()" style="@CssProvider.GetStyle()">
<div class="@CssProvider.GetClass("wrap")">
@ChildContent
</div>
</ShowTransitionElement>
</ExpandTransition>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,40 @@ public partial class BExpansionPanelContent : BDomComponentBase
[CascadingParameter]
public BExpansionPanel? ExpansionPanel { get; set; }

[Parameter]
public bool Eager { get; set; }

[Parameter]
public RenderFragment? ChildContent { get; set; }

private bool _isBooted;
private bool _booting;
private bool _isActive;

protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();

if (ExpansionPanel != null)
{
if ((_isBooted && _booting == false) || Eager)
{
_isActive = ExpansionPanel.InternalIsActive;
}
else if (ExpansionPanel.Booted)
{
_isBooted = true;
_booting = true;

if (ExpansionPanel.InternalIsActive)
{
await Task.Delay(16);

_booting = false;
_isActive = true;
}
}
}
}
}
}