33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
@typeparam TValue
|
|||
|
|
@inherits DInputBase<TValue>
|
||
|
|
@attribute [CascadingTypeParameter(nameof(TValue))]
|
||
|
|
|
||
|
|
@* daisyUI Radio: https://daisyui.com/components/radio/ . The group holds the bound value and cascades itself (not
|
||
|
|
fixed, so every DRadio re-renders with it); its radios share one name, the name attribute or a per-instance id.
|
||
|
|
It adds a div role="radiogroup" only when given attributes (a class, an aria-label). *@
|
||
|
|
<CascadingValue Value="this">
|
||
|
|
@if (AdditionalAttributes is null || AdditionalAttributes.Count == 0)
|
||
|
|
{
|
||
|
|
@ChildContent
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
<div @attributes="InputAttributes" role="radiogroup" class="@CssClass">
|
||
|
|
@ChildContent
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
</CascadingValue>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
||
|
|
|
||
|
|
readonly string uid = "d" + Guid.NewGuid().ToString("N")[..8];
|
||
|
|
|
||
|
|
internal string GroupName => string.IsNullOrEmpty(NameAttributeValue) ? uid : NameAttributeValue;
|
||
|
|
|
||
|
|
internal bool GroupInvalid => IsInvalid;
|
||
|
|
|
||
|
|
internal bool IsSelected(TValue value) => EqualityComparer<TValue>.Default.Equals(CurrentValue, value);
|
||
|
|
|
||
|
|
internal void Select(TValue value) => CurrentValue = value;
|
||
|
|
}
|