You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/Components/Select/Select.razor

49 lines
2.8 KiB

@namespace Connected.Components
@typeparam T
@inherits InputBase<T>
<CascadingValue Name="SubscribeToParentForm" Value="false" IsFixed="true">
<div class="mud-select" id="@_elementId">
<InputControl Label="@Label" Variant="@Variant" HelperText="@HelperText" HelperTextOnFocus="@HelperTextOnFocus" FullWidth="@FullWidth" Margin="@Margin" Class="@Classname" Style="@Style"
Error="@HasError" ErrorText="@ErrorText" ErrorId="@ErrorId" Disabled="@Disabled" @onclick="@ToggleMenu" Required="@Required" ForId="@FieldId">
<InputContent>
<Input @ref="_elementReference" InputType="@(CanRenderValue || (Strict && !IsValueInList) ? InputType.Hidden : InputType.Text)"
Class="mud-select-input" Margin="@Margin" Placeholder="@Placeholder"
Variant="@Variant"
TextUpdateSuppression="false"
Value="@(Strict && !IsValueInList ? null : Text)" DisableUnderLine="@DisableUnderLine"
Disabled="@Disabled" ReadOnly="true" Error="@HasError" ErrorId="@ErrorId"
OnAdornmentClick="@OnAdornmentClick" AdornmentIcon="@_currentIcon" Adornment="@Adornment"
AdornmentColor="@AdornmentColor" IconSize="@IconSize" AdornmentText="@AdornmentText"
Clearable="@Clearable" OnClearButtonClick="(async (e) => await SelectClearButtonClickHandlerAsync(e))"
@attributes="UserAttributes" OnBlur="@OnLostFocus">
@if (CanRenderValue)
{
@GetSelectedValuePresenter()
}
</Input>
<Popover Open=@(_isOpen) MaxHeight="@MaxHeight" AnchorOrigin="@AnchorOrigin" TransformOrigin="@TransformOrigin" Class="@PopoverClass" RelativeWidth="true">
<CascadingValue Value="@((ISelect)this)" IsFixed="true">
<List Clickable="true" Dense="@Dense" @bind-SelectedValue="_activeItemId">
@if (MultiSelection && SelectAll)
{
<ListItem Icon="@SelectAllCheckBoxIcon" Text="@SelectAllText" OnClick="SelectAllClickAsync" OnClickHandlerPreventDefault="true" Dense="@Dense" Class="mb-2" />
<Divider />
}
@ChildContent
</List>
</CascadingValue>
</Popover>
</InputContent>
</InputControl>
</div>
@*Shadow select items for IsValueInList and CanRenderValue*@
<CascadingValue Value="@((IShadowSelect)this)" IsFixed="true">
<CascadingValue Name="HideContent" Value="true">
@ChildContent
</CascadingValue>
</CascadingValue>
</CascadingValue>
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
<Overlay Visible="_isOpen" @onmousedown="@(() => CloseMenu(false))" LockScroll="@LockScroll" />