microsoft / fluentui-blazor

Microsoft Fluent UI Blazor components library. For use with ASP.NET Core Blazor applications
https://www.fluentui-blazor.net
MIT License
3.88k stars 377 forks source link

fix: No conditional ColumnOptions in TemplateColumn #2950

Closed AndreasTC closed 2 days ago

AndreasTC commented 3 days ago

🐛 Bug Report

I noticed that the component 'TemplateColumn' only accepts child content through the following top-level items: 'ChildContent', 'HeaderCellItemTemplate', 'ColumnOptions', 'PlaceholderTemplate'. For my certain usecase however, it would be handy if I could make my ColumnOptions contitional.

💻 Repro or Code Sample

<TemplateColumn 
    Title="TestColumn" 
    Sortable="true" 
    SortBy="@customSort(TestColumn)"
    >
    @if(SearchEnabled){
        <ColumnOptions>
            <div class="search-box">
                <FluentSearch ... />
            </div>
        </ColumnOptions>
    }

As for now, I could temporarely fix the issue by duplicating my entire TemplateColumn in my if-statement:

@if(SearchEnabled){
     <TemplateColumn ....>
           <ColumnOptions>
                   ...
           </ColumnOptions>
           ...
     </TemplateColumn>
}
else {
     <TemplateColumn ....>
          @* No ColumnOptions *@
           ...
     </TemplateColumn>
}

Note that if I place my if-statement inside the ColumnOptions-tag, i still get the filterIcon.

It could be that I'm missing something, but I didn't found a solution in the docs. Thanks in advance!

vnbaaij commented 2 days ago

Your temporary fix is actually the way you need to do this as we don't expose a parameter to conditionally render ColumnOptions