Skip to content

Commit

Permalink
tap to respond
Browse files Browse the repository at this point in the history
  • Loading branch information
erinnmclaughlin committed Apr 19, 2024
1 parent 76976c4 commit 6f59ce5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Site/Site.Client/Components/TerminalChat.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
flex-direction: column;
gap: 0.5em;
padding: 0.5em;
padding-bottom: 4rem;
}
22 changes: 16 additions & 6 deletions src/Site/Site.Client/Components/TerminalInput.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
<EditForm Model="this" OnValidSubmit="SubmitAsync" @onclick="FocusInputFieldAsync">
<AntiforgeryToken />
<DataAnnotationsValidator />
<InputText autocomplete="off" @ref="_inputField" @bind-Value="Message" @onclick:stopPropagation="true" />
@if (string.IsNullOrEmpty(Message))
{
<span class="instructions">Tap to respond.</span>
}
<input autocomplete="off" @ref="_inputField" @bind-value="Message" @bind-value:event="oninput" />
</EditForm>
</div>

@code {

private InputText? _inputField;
private ElementReference _inputField;

[Required]
private string Message { get; set; } = string.Empty;
Expand All @@ -22,18 +26,24 @@
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await FocusInputFieldAsync();
{
await InvokeAsync(async () =>
{
await FocusInputFieldAsync();
StateHasChanged();
});
}
}

private async Task FocusInputFieldAsync()
{
if (_inputField?.Element is not null)
await _inputField.Element.Value.FocusAsync();
await _inputField.FocusAsync();
}

private async Task SubmitAsync()
{
await OnUserInputReceived.InvokeAsync(Message);
if (!string.IsNullOrWhiteSpace(Message))
await OnUserInputReceived.InvokeAsync(Message);
}

}
23 changes: 23 additions & 0 deletions src/Site/Site.Client/Components/TerminalInput.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,27 @@ div ::deep form {
padding: 0;
color: transparent;
text-shadow: 0 0 0 white;
position: relative;
}


div ::deep input::before {
content: '(Tap to respond)';
position: absolute;
height: 100%;
width: 100%;
color: red;
}

.instructions {
position: absolute;
opacity: 0.25;
color: lime;
}

@media only screen and (min-width: 600px) {

.instructions {
display: none;
}
}

0 comments on commit 6f59ce5

Please sign in to comment.