Rework for Tabstrip regression issue

Fix for Tabpanel is not updating the UI. #4778 #4828
This commit is contained in:
Leigh Pointer
2024-11-26 15:39:51 +01:00
parent 9d7549da70
commit a845dd1976
5 changed files with 41 additions and 29 deletions

View File

@ -7,7 +7,7 @@
@inject IStringLocalizer<SharedResources> SharedLocalizer
<div class="quill-text-editor">
<TabStrip ActiveTab="@_activetab">
<TabStrip ActiveTab="@_activetab" TabChangeEvent=false>
@if (_allowRichText)
{
<TabPanel Name="Rich" Heading="Rich Text Editor" ResourceKey="RichTextEditor">

View File

@ -10,13 +10,13 @@
<li class="nav-item" @key="tabPanel.Name">
@if (tabPanel.Name.ToLower() == ActiveTab.ToLower())
{
<a class="nav-link active" data-bs-toggle="tab" href="#@(Id + tabPanel.Name)" role="tab" @onclick:preventDefault="true">
<a class="nav-link active" data-bs-toggle="tab" href="#@(Id + tabPanel.Name)" role="tab" @onclick="() => { if (TabChangeEvent) ChangeTab(tabPanel.Name); }">
@tabPanel.DisplayHeading()
</a>
}
else
{
<a class="nav-link" data-bs-toggle="tab" href="#@(Id + tabPanel.Name)" role="tab" @onclick:preventDefault="true">
<a class="nav-link" data-bs-toggle="tab" href="#@(Id + tabPanel.Name)" role="tab" @onclick="() => { if (TabChangeEvent) ChangeTab(tabPanel.Name); }">
@tabPanel.DisplayHeading()
</a>
}
@ -32,34 +32,37 @@
</CascadingValue>
@code {
private List<TabPanel> _tabPanels;
private string _tabpanelid = string.Empty;
private List<TabPanel> _tabPanels;
private string _tabpanelid = string.Empty;
[Parameter]
public RenderFragment ChildContent { get; set; } // contains the TabPanels
[Parameter]
public RenderFragment ChildContent { get; set; } // contains the TabPanels
[Parameter]
public string ActiveTab { get; set; } // optional - defaults to first TabPanel if not specified. Can also be set using a "tab=" querystring parameter.
[Parameter]
public bool TabChangeEvent { get; set; } = true;
[Parameter]
public bool Refresh { get; set; } // optional - used in scenarios where TabPanels are added/removed dynamically within a parent form. ActiveTab may need to be reset as well when this property is used.
[Parameter]
public string ActiveTab { get; set; } // optional - defaults to first TabPanel if not specified. Can also be set using a "tab=" querystring parameter.
[Parameter]
public string Id { get; set; } // optional - used to uniquely identify an instance of a tab strip component (will be set automatically if no value provided)
[Parameter]
public bool Refresh { get; set; } // optional - used in scenarios where TabPanels are added/removed dynamically within a parent form. ActiveTab may need to be reset as well when this property is used.
[Parameter]
public string Id { get; set; } // optional - used to uniquely identify an instance of a tab strip component (will be set automatically if no value provided)
[Parameter]
public string TabContentClass { get; set; } // optional - to extend the TabContent div.
protected override void OnInitialized()
{
if (string.IsNullOrEmpty(Id))
{
// create unique id for component
Id = "TabStrip_" + Guid.NewGuid().ToString("N") + "_" ;
}
}
protected override void OnParametersSet()
protected override void OnInitialized()
{
if (string.IsNullOrEmpty(Id))
{
// create unique id for component
Id = "TabStrip_" + Guid.NewGuid().ToString("N") + "_";
}
}
protected override void OnParametersSet()
{
if (PageState.QueryString.ContainsKey("tab"))
{
@ -69,6 +72,7 @@
{
_tabPanels = new List<TabPanel>();
}
StateHasChanged();
}
internal void AddTabPanel(TabPanel tabPanel)
@ -110,4 +114,13 @@
}
return authorized;
}
private void ChangeTab(string tabName)
{
if (ActiveTab != tabName)
{
ActiveTab = tabName;
StateHasChanged();
}
}
}