-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathSearchInput.razor
More file actions
33 lines (26 loc) · 924 Bytes
/
Copy pathSearchInput.razor
File metadata and controls
33 lines (26 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<div class="search-bar">
<input type="text" class="search-bar-input" placeholder="search" aria-label="search" @bind-value="searchTerm"
@onkeyup="@CheckForEnter" title="Search for blog post via title or tags"/>
<button class="search-bar-button" aria-label="search submit" @onclick="CallSearchEntered"><i class="search"></i></button>
</div>
@code {
private string searchTerm = string.Empty;
[Parameter]
public EventCallback<string> SearchEntered { get; set; }
private async Task CallSearchEntered()
{
if (string.IsNullOrWhiteSpace(searchTerm))
{
return;
}
var trimmed = searchTerm.Trim();
await SearchEntered.InvokeAsync(trimmed);
}
private async Task CheckForEnter(KeyboardEventArgs e)
{
if (e.Code is "Enter" or "NumpadEnter")
{
await SearchEntered.InvokeAsync(searchTerm);
}
}
}