Class ElementReferenceExtensions
Extends ElementReference with some helper methods to focus elements in a more robust way, or to focus the first/last focusable child of an element.
public static class ElementReferenceExtensions
- Inheritance
-
ElementReferenceExtensions
- Inherited Members
Methods
FocusFirstFocusableChild(ElementReference, IJSRuntime, CancellationToken)
Focuses the first "focusable" element child. This includes inputs, selects, buttons, inputs, etc. Elements with tabindex="-1" are filtered. See also FocusFirstFocusableChild(ElementReference, IJSRuntime, CancellationToken).
public static ValueTask FocusFirstFocusableChild(this ElementReference el, IJSRuntime js, CancellationToken ct = default)
Parameters
elElementReferencejsIJSRuntimectCancellationToken
Returns
FocusLastFocusableChild(ElementReference, IJSRuntime, CancellationToken)
Focuses the last "focusable" element child. This includes inputs, selects, buttons, inputs, etc. Elements with tabindex="-1" are filtered. See also FocusFirstFocusableChild(ElementReference, IJSRuntime, CancellationToken).
public static ValueTask FocusLastFocusableChild(this ElementReference el, IJSRuntime js, CancellationToken ct = default)
Parameters
elElementReferencejsIJSRuntimectCancellationToken
Returns
ForceFocus(ElementReference, IJSRuntime, int, CancellationToken)
Sometimes a simple FocusAsync is not enough to focus an element
because there are multiple components fighting over the focus
asynchronously. While that may be something that in theory should be
fixed at its root, this is often rather difficult
This method fights the symptoms by simply re-focusing the element
n times (with a delay of 10ms) until it is focused.
public static ValueTask ForceFocus(this ElementReference el, IJSRuntime js, int retries = 5, CancellationToken ct = default)
Parameters
elElementReferencejsIJSRuntimeretriesintctCancellationToken
Returns
RestoreFocus(ElementReference, IJSRuntime, CancellationToken)
public static ValueTask RestoreFocus(this ElementReference el, IJSRuntime js, CancellationToken ct = default)
Parameters
elElementReferencejsIJSRuntimectCancellationToken
Returns
SaveFocus(ElementReference, IJSRuntime, CancellationToken)
Store the currently focused element (document.activeElement) as a
js field of the given element. You can call RestoreFocus(ElementReference, IJSRuntime, CancellationToken)
to then restore focus to that element later.
public static ValueTask SaveFocus(this ElementReference el, IJSRuntime js, CancellationToken ct = default)
Parameters
elElementReferencejsIJSRuntimectCancellationToken