Skip to content

feat: add custom ItemProvider to FluentCombobox #3596

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

Open
MarvinKlein1508 opened this issue Mar 31, 2025 · 4 comments
Open

feat: add custom ItemProvider to FluentCombobox #3596

MarvinKlein1508 opened this issue Mar 31, 2025 · 4 comments
Labels
triage New issue. Needs to be looked at v5 For the next major version

Comments

@MarvinKlein1508
Copy link
Contributor

🙋 Feature Request

The FluentCombobox only allows you to define a pre-existing list of items. This limits the usability of this component a lot. It would be great if this component would also allow a custom item provider like FluentAutocomplete.

If both components would offer this feature it would be much easier to bind to a single object. If you rely on a custom item provider this currently only possible with the FluentAutocomplete which requires some hacky tricks to achieve this behaviour.

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Mar 31, 2025
@vnbaaij vnbaaij added the v5 For the next major version label Apr 1, 2025
@vnbaaij
Copy link
Collaborator

vnbaaij commented Apr 1, 2025

Done for V5. See https://fluentui-blazor-v5.azurewebsites.net/List/Combobox

Don't think we will be adding this for v4 anymore

@MarvinKlein1508
Copy link
Contributor Author

@vnbaaij where is it in V5? The link only has documentation for IEnumerable<TItem> but not for a custom method which gets invoked while typing.

PS: I can live with V5 only :)

@MarvinKlein1508
Copy link
Contributor Author

What I mean is some kind of way like this example from FluentAutocomplete

@using System.Globalization
@inject DataSource Data

<FluentStack Orientation="Orientation.Vertical" VerticalGap="10">

    @* Immediate Delay *@
    <FluentNumberField @bind-Value="_immediateDelay"
                       TValue="int"
                       Label="Immediate Delay"
                       Placeholder="Delay"
                       Min="0"
                       Max="2000"
                       Step="100" />

    
    <FluentAutocomplete TOption="CultureInfo"
                        ImmediateDelay="_immediateDelay"
                        AutoComplete="off"
                        Label="Select Culture"
                        Width="250px"
                        OnOptionsSearch="OnSearch"
                        Placeholder="Select countries"
                        MaximumOptionsSearch="int.MaxValue"
                        MaximumSelectedOptions="2"
                        Virtualize="true"
                        OptionText="@(item => $"{item.DisplayName} - {item.Name}")"
                        @bind-SelectedOptions="@SelectedCultures" />

</FluentStack>




<p>
    <b>Selected</b>: @(String.Join(" - ", SelectedCultures.Select(i => i.Name)))
</p>

@code
{
    private int _immediateDelay;

    IEnumerable<CultureInfo> SelectedCultures = Array.Empty<CultureInfo>();
    CultureInfo[] Cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

    private void OnSearch(OptionsSearchEventArgs<CultureInfo> e)
    {
        e.Items = Cultures.Where(culture =>
            culture.Name.Contains(e.Text, StringComparison.OrdinalIgnoreCase) ||
            culture.DisplayName.Contains(e.Text, StringComparison.OrdinalIgnoreCase));
    }
}

Within OnSearch I do a query against the database because I don't want to fetch 3000 items into memory at once.

@vnbaaij
Copy link
Collaborator

vnbaaij commented Apr 1, 2025

Sorry, I thought you meant to just have the Items. @dvoituron can we add OnSearch too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New issue. Needs to be looked at v5 For the next major version
Projects
None yet
Development

No branches or pull requests

2 participants