Skip to content

Commit 2101978

Browse files
committed
Typeahead exposed OnFocus event.
1 parent 6d062f7 commit 2101978

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

src/Majorsoft.Blazor.Components.TestApps.Common/Components/Typeahead.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ textarea {
8989
AccentColor="@_accentColor"
9090
OnSelectedItemChanged="@(text => SelectedItemChanged(text))"
9191
OnDropdownOpen="@(() => WriteEventLog("TypeaheadInput: dropdown opened"))"
92-
OnDropdownClose="@(() => WriteEventLog("TypeaheadInput: dropdown closed"))">
92+
OnDropdownClose="@(() => WriteEventLog("TypeaheadInput: dropdown closed"))"
93+
OnFocus="@(() => WriteEventLog("TypeaheadInput: textbox focused"))">
9394
</TypeaheadInput>
9495
</div>
9596
</div>

src/Majorsoft.Blazor.Components.Typeahead/TypeaheadInput.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
OnValueChanged="e => OnValueChanged(e)"
1212
ForceNotifyByEnter="false"
1313
ForceNotifyOnBlur="false"
14-
@onkeydown="OnKeyDown" @onfocus="OnFocus"
14+
@onkeydown="OnKeyDown" @onfocus="OnFocused"
1515
autocomplete="off"
1616
@attributes=AdditionalAttributes />
1717

src/Majorsoft.Blazor.Components.Typeahead/TypeaheadInput.razor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ private string GetDropdownWidth()
179179
[Parameter] public EventCallback<TItem> OnSelectedItemChanged { get; set; }
180180
[Parameter] public EventCallback OnDropdownOpen { get; set; }
181181
[Parameter] public EventCallback OnDropdownClose { get; set; }
182+
[Parameter] public EventCallback<FocusEventArgs> OnFocus { get; set; }
182183

183184
[Parameter(CaptureUnmatchedValues = true)]
184185
public Dictionary<string, object> AdditionalAttributes { get; set; }
@@ -305,14 +306,20 @@ private async Task OnKeyDown(KeyboardEventArgs e)
305306
}
306307
}
307308
}
308-
private async Task OnFocus(FocusEventArgs e)
309+
private async Task OnFocused(FocusEventArgs e)
309310
{
310-
WriteDiag($"{nameof(OnFocus)} event: '{e.Type}'.");
311+
WriteDiag($"{nameof(OnFocused)} event: '{e.Type}'.");
311312
_hasNoResult = false;
312313

313314
await _clickHandler.RegisterClickBoundariesAsync(_typeahead.InnerElementReference, OnOutsideClick, OnInsideClick);
314315

315316
await Activate();
317+
318+
if (OnFocus.HasDelegate)
319+
{
320+
WriteDiag($"{nameof(OnFocus)} delegate: '{e.Type}'.");
321+
await OnFocus.InvokeAsync(e);
322+
}
316323
}
317324
private async Task OnOutsideClick(MouseEventArgs e)
318325
{

src/Majorsoft.Blazor.Components.Typeahead/TypeaheadInputText.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
OnValueChanged="e => OnValueChanged(e)"
1212
ForceNotifyByEnter="false"
1313
ForceNotifyOnBlur="false"
14-
@onkeydown="OnKeyDown" @onfocus="OnFocus"
14+
@onkeydown="OnKeyDown" @onfocus="OnFocused"
1515
autocomplete="off"
1616
@attributes=AdditionalAttributes />
1717

src/Majorsoft.Blazor.Components.Typeahead/TypeaheadInputText.razor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private string GetDropdownWidth()
180180
[Parameter] public EventCallback<TItem> OnSelectedItemChanged { get; set; }
181181
[Parameter] public EventCallback OnDropdownOpen { get; set; }
182182
[Parameter] public EventCallback OnDropdownClose { get; set; }
183+
[Parameter] public EventCallback<FocusEventArgs> OnFocus { get; set; }
183184

184185
[Parameter(CaptureUnmatchedValues = true)]
185186
public Dictionary<string, object> AdditionalAttributes { get; set; }
@@ -306,14 +307,20 @@ private async Task OnKeyDown(KeyboardEventArgs e)
306307
}
307308
}
308309
}
309-
private async Task OnFocus(FocusEventArgs e)
310+
private async Task OnFocused(FocusEventArgs e)
310311
{
311-
WriteDiag($"{nameof(OnFocus)} event: '{e.Type}'.");
312+
WriteDiag($"{nameof(OnFocused)} event: '{e.Type}'.");
312313
_hasNoResult = false;
313314

314315
await _clickHandler.RegisterClickBoundariesAsync(_typeahead.InnerElementReference, OnOutsideClick, OnInsideClick);
315316

316317
await Activate();
318+
319+
if (OnFocus.HasDelegate)
320+
{
321+
WriteDiag($"{nameof(OnFocus)} delegate: '{e.Type}'.");
322+
await OnFocus.InvokeAsync(e);
323+
}
317324
}
318325
private async Task OnOutsideClick(MouseEventArgs e)
319326
{

0 commit comments

Comments
 (0)