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)
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: stickydid not work for me. As a workaround I have added the classoverflow-columnto thoseTemplateColumns which contains FluentSelect components and added the following component css rule.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.razor.css file:
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
@ehsangfl More info here: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-7.0
Hi,
You need to add an isolated css file to your component and then target the listbox part of the select. Something like