fluentui-blazor: fix: FluentSelect does not work inside FluentDataGrid

๐Ÿ› Bug Report

When using FluentSelect inside FluentDataGrid dropdown is not shown.

๐Ÿ’ป Repro or Code Sample

Based on these examples:

https://brave-cliff-0c0c93310.azurestaticapps.net/SelectPage

https://brave-cliff-0c0c93310.azurestaticapps.net/DatagridPage

I would also like some better examples working with enum values and select. I had to write my own code but I think this should be documented better. Added MatSelectItem as example since it works with FluentDataGrid. Select works fine with Enum when not used in FluentDataGrid

<p>
    <MatSelectItem @bind-Value="@threatDto.Severity" Label="Severity" Items="@SeverityValues" FullWidth="true" Required="true">
    </MatSelectItem>
</p>
<p>
    <FluentSelect @bind-Value="@threatDto.Severity" Options="@SeverityOptionList" Required="true">
    </FluentSelect>
</p>

<FluentDataGrid id="ExternalLinksGrid" RowsData=RowsGrid1 ColumnDefinitions=ExternalLinkColumns GridTemplateColumns="1fr 1fr" TItem=ExternalLink Context="tableRowContext">
    <RowItemTemplate>
        <FluentDataGridRow>
            <FluentDataGridCell GridColumn=1>
                <FluentTextField @bind-Value=@tableRowContext.Link></FluentTextField>
            </FluentDataGridCell>
            <FluentDataGridCell GridColumn=2>
                <FluentSelect @bind-Value="@tableRowContext.LinkType" Options="@LinkTypeOptionList" Required="true">
                </FluentSelect>
            </FluentDataGridCell>
            <FluentDataGridCell GridColumn=3>
                <MatSelectItem @bind-Value="@tableRowContext.LinkType" Label="LinkType" Items="@LinkTypeValues" Required="true">
                </MatSelectItem>
            </FluentDataGridCell>
        </FluentDataGridRow>
    </RowItemTemplate>
</FluentDataGrid>
		

public List<ColumnDefinition<ExternalLink>> ExternalLinkColumns = new();			

List<Severity?> SeverityValues = Enum.GetValues(typeof(Severity)).Cast<Severity?>().Where(x => x != Severity.None).ToList();

List<LinkType?> LinkTypeValues = Enum.GetValues(typeof(LinkType)).Cast<LinkType?>().Where(x => x != LinkType.None).ToList();

List<Option<Severity?>> SeverityOptionList = Enum.GetValues(typeof(Severity)).Cast<Severity?>().Where(x => x != Severity.None).Select(x => new Option<Severity?> { Key = x.Value, Value = x.Value }).ToList();

List<Option<LinkType?>> LinkTypeOptionList = Enum.GetValues(typeof(LinkType)).Cast<LinkType?>().Where(x => x != LinkType.None).Select(x => new Option<LinkType?> { Key = x, Value = x }).ToList();

List<ExternalLink> RowsGrid1 = new()
{
    new ExternalLink(){ Link = "123", LinkType = LinkType.JiraRisk},
    new ExternalLink(){ Link = "12345", LinkType = LinkType.OtherHyperlink},
};

protected override void OnInitialized()
{
    ExternalLinkColumns.Add(new ColumnDefinition<ExternalLink>("Link", x => x.Link));
    ExternalLinkColumns.Add(new ColumnDefinition<ExternalLink>("Link Type", x => x.LinkType));
    ExternalLinkColumns.Add(new ColumnDefinition<ExternalLink>("Link Type MatSelectItem", x => x.LinkType));
}

Classes:

[Required, EnumDataType(typeof(Severity))]
public Severity? Severity { get; set; }		

public class ExternalLink : Entity
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    [Required]
    [MaxLength(2048)]
    public string Link { get; set; }

    [Required, EnumDataType(typeof(LinkType))]
    public LinkType? LinkType { get; set; }

}

public enum LinkType
{
    None = 0,
    OtherHyperlink = 1,
    JiraIssue = 2,
    JiraRisk = 3,
}

๐Ÿค” Expected Behavior

Should render drop down on click

๐Ÿ˜ฏ Current Behavior

No drop down is visible

๐Ÿ’ Possible Solution

๐Ÿ”ฆ Context

I can not use Fluent UI alone

๐ŸŒ Your Environment

  • OS & Device: Windows
  • Browser Chrome
  • .NET and FAST Version .NET 6, Microsoft.Fast.Components.FluentUI 1.5.1 @fluentui/web-components 2.5.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 32 (17 by maintainers)

Most upvoted comments

Sorry, tried what? The workaround with the overflow?

As I explained, I think having an editable grid is not a good idea in general. But doing it on a virtualized grid with (potentially) a huge amount of rows is definitely a very bad idea. (huge load on the DOM)

Yes exactly. It might technically be a bad idea but inline editing is something that users really like. Like the example with template columns.

https://www.fluentui-blazor.net/DataGrid#templatecolumns2

position: sticky did not work for me. As a workaround I have added the class overflow-column to those TemplateColumns which contains FluentSelect components and added the following component css rule.

<TemplateColumn Title="Column with overflow content" Class="overflow-column">
    <FluentSelect ... />
</TemplateColumn>
::deep fluent-data-grid-cell.overflow-column {
    overflow: visible;
    max-width: 0;
}

As a side effect, when there is not enouph space, a horizontal scrollbar will be shown. But that is fine for my use case.

I believe this is an issue in the underlying web components. Have raised an issue there,

Tried the fix. After surrounding the FluentDataGrid with div it worked.

page.razor file:

@page "/component"

<div>
    <FluentDataGrid Items="@people">
        <PropertyColumn Property="@(p => p.PersonId)" />
        <PropertyColumn Property="@(p => p.Name)" />
        <PropertyColumn Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" />
        <TemplateColumn Context="context" Title="Job" Class="overflow-column">
            <FluentSelect Items=@stringOptions1 OptionText="@(o => o.Text)" OptionValue="@(o => o.Value)" TOption="Option<string>" Position="SelectPosition.Above" @bind-Value="@context.Job"></FluentSelect>
        </TemplateColumn>
    </FluentDataGrid>
</div>

@code {

    IQueryable<Person> people = new[]
    {
        new Person(10895, "Jean Martin", new DateOnly(1985, 3, 16), "Driver"),
        new Person(10944, "Antรณnio Langa", new DateOnly(1991, 12, 1), "Woodworker"),
        new Person(11203, "Julie Smith", new DateOnly(1958, 10, 10), "Driver"),
        new Person(11205, "Nur Sari", new DateOnly(1922, 4, 27), "Woodworker"),
        new Person(11898, "Jose Hernandez", new DateOnly(2011, 5, 3), "Doctor"),
        new Person(12130, "Kenji Sato", new DateOnly(2004, 1, 9), "Woodworker"),
    }.AsQueryable();

    List<Option<string>> stringOptions1 = new()
    {
        { new Option<string> { Value = "Driver", Text = "Driver" } },
        { new Option<string> { Value = "Doctor", Text = "Doctor" } },
        { new Option<string> { Value = "Woodworker", Text = "Woodworker" } }
    };
}

page.razor.css file:

::deep .overflow-column {
    overflow: visible !important;
}

Donโ€™t know why but if you put the align left inside a span, it works.

To be honest, my knowledge of css is on a good day, crap ๐Ÿ˜‚

Style seems to have incorrect identifier or what itโ€™s called, fluent-data-grid-cell. I didnโ€™t get it to work how hard I tried to figure it out. Just add style=โ€œoverflow: visible;โ€ to the TemplateColumn

Hi,

You need to add an isolated css file to your component and then target the listbox part of the select. Something like

 :deep .{classname} ::part(listbox) {
   position: sticky
}