Checkbox - working example -- NumberInput,TextInput - InputAttributes initialization moved to InputBase class #8
Merged
koma
merged 4 commits from features/rewrite/checkbox
into features/rewrite/main
2 years ago
@ -0,0 +1,13 @@
|
||||
@using Connected.Models;
|
||||
|
||||
@inherits InputBase;
|
||||
|
||||
<div class="checkbox-group">
|
||||
@if (Checked)
|
||||
{
|
||||
<input id="@Id" name="checkbox" type="checkbox" @onchange="OnChange" @attributes=@InputAttributes checked>
|
||||
} else {
|
||||
<input id="@Id" name="checkbox" type="checkbox" @onchange="OnChange" @attributes=@InputAttributes>
|
||||
}
|
||||
<label for="@Id" class="checkbox-label">@Label</label>
|
||||
</div>
|
@ -0,0 +1,9 @@
|
||||
@using Connected.Models;
|
||||
|
||||
@inherits InputBase;
|
||||
|
||||
<div>
|
||||
<div class="container">
|
||||
@ChildContent
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,8 @@
|
||||
@using Connected.Models;
|
||||
|
||||
@inherits InputBase;
|
||||
|
||||
<div class="radio-group">
|
||||
<input id="@Id" name="@ParentRadioGroup.Name" type="radio" @onchange="OnChange" @attributes=@InputAttributes>
|
||||
<label for="@Id" class="radio-label">@Label</label>
|
||||
</div>
|
@ -0,0 +1,15 @@
|
||||
@using Connected.Models;
|
||||
|
||||
@inherits InputBase;
|
||||
|
||||
<CascadingValue Value="this">
|
||||
<div>
|
||||
@if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
<h5>@Name</h5>
|
||||
}
|
||||
<div class="container">
|
||||
@ChildContent
|
||||
</div>
|
||||
</div>
|
||||
</CascadingValue>
|
@ -56,14 +56,13 @@ public partial class TextInput: InputBase
|
|||||||
|
|||||||
}
|
|||||||
|
|||||||
protected override async Task OnParametersSetAsync()
|
|||||||
protected override async Task OnInitializedAsync()
|
|||||||
{
|
|||||||
if (base.InputAttributes is null) base.InputAttributes = new();
|
|||||||
if (base.Required)
|
|||||||
await base.OnInitializedAsync();
|
|||||||
if (Required)
|
|||||||
|
|||||||
{
|
|||||||
if (base.InputAttributes.ContainsKey("required")) base.InputAttributes.Add("required", true);
|
|||||||
if (!InputAttributes.ContainsKey("required")) InputAttributes.Add("required", true);
|
|||||||
koma
commented 2 years ago
Review
See here |
|||||||
}
|
|||||||
await base.OnInitializedAsync();
|
|||||||
}
|
|||||||
|
|||||||
}
|
@ -1,7 +1,5 @@
|
|||||||
using Connected.Utilities;
|
|||||||
koma
commented 2 years ago
Review
The line contains an invisible Unicode character that should definitely not be there. |
|||||||
using Microsoft.AspNetCore.Components;
|
|||||||
using static Connected.Colors;
|
|||||||
using static System.Net.Mime.MediaTypeNames;
|
|||||||
|
|||||||
namespace Connected.Models;
|
|||||||
public class InputBase : ComponentBase
|
|||||||
@ -124,4 +122,9 @@ public class InputBase : ComponentBase
|
|||||||
|
|||||||
[Parameter]
|
|||||||
public string Placeholder { get; set; } = string.Empty;
|
|||||||
koma
commented 2 years ago
Review
Should probably be null if uninitialized. Minor detail. |
|||||||
|
|||||||
protected override async Task OnInitializedAsync()
|
|||||||
{
|
|||||||
if (InputAttributes is null) InputAttributes = new();
|
|||||||
koma
commented 2 years ago
Review
Single line if statements should be braceless, but not inlined, e.g.
instead of
|
|||||||
}
|
|||||||
}
|
|||||||
|
Loading…
Reference in new issue
Nested ifs should be joined in single condition, especially if all are single-lined.