Skip to content

Commit

Permalink
Set focus to input after Scrub
Browse files Browse the repository at this point in the history
  • Loading branch information
menees committed Oct 24, 2023
1 parent eb84585 commit baca1f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Menees.Chords.Web/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<option value="General">General</option>
<option value="ChordPro">ChordPro</option>
</select>
<button class="btn btn-secondary text-nowrap" @onclick="CleanInput">
<button class="btn btn-secondary text-nowrap" @onclick="CleanInputAsync">
<i class="oi oi-minus"></i> Scrub
</button> <button class="btn btn-primary text-nowrap" @onclick="ConvertInput">
<i class="oi oi-share"></i> Convert
Expand All @@ -26,7 +26,7 @@
<div class="row">
<div class="col">
<textarea @bind="@Input" @bind:event=@InputChangeEvent spellcheck="false" wrap="hard"
class="form-control font-monospace mono-font w-100 h-most"></textarea>
class="form-control font-monospace mono-font w-100 h-most" @ref="inputElement"></textarea>
</div>
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/Menees.Chords.Web/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public sealed partial class Index : IDisposable
private bool whenTyping = true;
private CopyState copyState = new("Copy", "oi oi-clipboard", "btn-secondary");
private string? title;
private ElementReference? inputElement;

#endregion

Expand Down Expand Up @@ -213,18 +214,22 @@ private async Task CopyToClipboardAsync()
}
}

private async void DownloadAsync()
private async Task DownloadAsync()
{
// https://www.meziantou.net/generating-and-downloading-a-file-in-a-blazor-webassembly-application.htm
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(this.output);
string fileName = string.IsNullOrEmpty(this.title) ? $"{this.toType}.cho" : $"{this.title}.cho";
await this.JavaScript.InvokeVoidAsync("BlazorDownloadFile", fileName, "text/plain", fileBytes);
}

private void CleanInput()
private async Task CleanInputAsync()
{
Cleaner cleaner = new(this.Input);
this.Input = cleaner.CleanText;
if (this.inputElement != null)
{
await this.inputElement.Value.FocusAsync();
}
}

#endregion
Expand Down

0 comments on commit baca1f5

Please sign in to comment.