-
-
Notifications
You must be signed in to change notification settings - Fork 364
feat(MultiSelectGeneric): add MultiSelectGeneric component #6103
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
src/BootstrapBlazor/Components/SelectGeneric/MultiSelectGeneric.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| @namespace BootstrapBlazor.Components | ||
| @using Microsoft.AspNetCore.Components.Web.Virtualization | ||
| @typeparam TValue | ||
| @inherits SelectBase<List<TValue>> | ||
| @attribute [BootstrapModuleAutoLoader("Select/MultiSelect.razor.js", JSObjectReference = true)] | ||
|
|
||
| @if (IsShowLabel) | ||
| { | ||
| <BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText"></BootstrapLabel> | ||
| } | ||
| <div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id" data-bb-scroll-behavior="@ScrollIntoViewBehaviorString"> | ||
| <div class="@ToggleClassString" data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-auto-close="outside" data-bs-custom-class="@CustomClassString" tabindex="0"> | ||
| <div class="@PlaceHolderClassString">@PlaceHolder</div> | ||
| <div class="multi-select-items"> | ||
| @if (DisplayTemplate != null) | ||
| { | ||
| @DisplayTemplate(SelectedItems) | ||
| } | ||
| else | ||
| { | ||
| foreach (var item in SelectedItems) | ||
| { | ||
| if (ShowCloseButton) | ||
| { | ||
| <div class="multi-select-item-group"> | ||
| <DynamicElement TagName="span" class="multi-select-close" | ||
| TriggerClick="@(!IsPopover)" OnClick="() => ToggleRow(item)"> | ||
| <i class="@CloseButtonIcon"></i> | ||
| </DynamicElement> | ||
| <span class="multi-select-item">@item.Text</span> | ||
| </div> | ||
| } | ||
| else | ||
| { | ||
| <span class="multi-select-item">@item.Text</span> | ||
| } | ||
| } | ||
| } | ||
| </div> | ||
| @if (!IsSingleLine) | ||
| { | ||
| <span class="@AppendClassString"><i class="@DropdownIcon"></i></span> | ||
| } | ||
| </div> | ||
| @if (GetClearable()) | ||
| { | ||
| <span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span> | ||
| } | ||
| <div class="@DropdownMenuClassString"> | ||
| @if (ShowSearch) | ||
| { | ||
| <div class="dropdown-menu-search"> | ||
| <input type="text" class="search-text form-control" autocomplete="off" value="@SearchText" aria-label="search" /> | ||
| <i class="@SearchIconString"></i> | ||
| <i class="@SearchLoadingIconString"></i> | ||
| </div> | ||
| } | ||
| @if (ShowToolbar) | ||
| { | ||
| <div class="toolbar"> | ||
| @if (ShowDefaultButtons) | ||
| { | ||
| <DynamicElement TagName="button" type="button" class="btn" OnClick="SelectAll">@SelectAllText</DynamicElement> | ||
| <DynamicElement TagName="button" type="button" class="btn" OnClick="InvertSelect">@ReverseSelectText</DynamicElement> | ||
| <DynamicElement TagName="button" type="button" class="btn" OnClick="Clear">@ClearText</DynamicElement> | ||
| } | ||
| @ButtonTemplate | ||
| </div> | ||
| } | ||
| @if (IsVirtualize) | ||
| { | ||
| <div class="dropdown-menu-body dropdown-virtual"> | ||
| @if (OnQueryAsync == null) | ||
| { | ||
| <Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" Items="@GetVirtualItems()" ChildContent="RenderRow"> | ||
| </Virtualize> | ||
| } | ||
| else | ||
| { | ||
| <Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" ItemsProvider="LoadItems" | ||
| Placeholder="RenderPlaceHolderRow" ItemContent="RenderRow" @ref="_virtualizeElement"> | ||
| </Virtualize> | ||
| } | ||
| </div> | ||
| } | ||
| else if (Rows.Count == 0) | ||
| { | ||
| <div class="dropdown-item">@NoSearchDataText</div> | ||
| } | ||
| else | ||
| { | ||
| <div class="dropdown-menu-body"> | ||
| @foreach (var itemGroup in Rows.GroupBy(i => i.GroupName)) | ||
| { | ||
| if (!string.IsNullOrEmpty(itemGroup.Key)) | ||
| { | ||
| if (GroupItemTemplate != null) | ||
| { | ||
| @GroupItemTemplate(itemGroup.Key) | ||
| } | ||
| else | ||
| { | ||
| <Divider Text="@itemGroup.Key" /> | ||
| } | ||
| } | ||
| @foreach (var item in itemGroup) | ||
| { | ||
| @RenderRow(item) | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(itemGroup.Key)) | ||
| { | ||
| if (GroupItemTemplate != null) | ||
| { | ||
| @GroupItemTemplate(itemGroup.Key) | ||
| } | ||
| else | ||
| { | ||
| <Divider Text="@itemGroup.Key" /> | ||
| } | ||
| } | ||
| } | ||
| </div> | ||
| } | ||
| </div> | ||
| </div> | ||
|
|
||
| @code { | ||
| RenderFragment<SelectedItem<TValue>> RenderRow => item => | ||
| @<DynamicElement OnClick="() => ToggleRow(item)" TriggerClick="@CheckCanTrigger(item)" class="@GetItemClassString(item)"> | ||
| <div class="multi-select-item"> | ||
| <div class="form-check"> | ||
| <input class="form-check-input" type="checkbox" disabled="@CheckCanSelect(item)" checked="@GetCheckedString(item)" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): The checked attribute is set as a string, which may cause issues. Blazor checkboxes require a boolean for the 'checked' attribute. Update GetCheckedState to return a boolean and bind it directly to 'checked'. |
||
| </div> | ||
| @if (ItemTemplate != null) | ||
| { | ||
| @ItemTemplate(item) | ||
| } | ||
| else if (IsMarkupString) | ||
| { | ||
| @((MarkupString)item.Text) | ||
| } | ||
| else | ||
| { | ||
| <span>@item.Text</span> | ||
| } | ||
| </div> | ||
| </DynamicElement>; | ||
|
|
||
| RenderFragment<PlaceholderContext> RenderPlaceHolderRow => context => | ||
| @<div class="dropdown-item"> | ||
| <div class="is-ph"></div> | ||
| </div>; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Group dividers are rendered both before and after each group.
Rendering dividers both before and after each group can create duplicates. Consider rendering a divider only before each group except the first, or after each group except the last, to avoid unnecessary dividers.