/// <summary> /// Scrolls inside the given parent element to the given first found inner element by class name. /// </summary> /// <param name="parent">Blazor reference to an HTML (outer/wrapper) element</param> /// <param name="className">Inner element CSS class to scroll to</param> /// <returns>Async Task</returns> public static async Task ScrollInParentByClassAsync(this ElementReference parent, string className) { await using (var module = await parent.GetJsObject()) { if (module is not null) { await module.InvokeVoidAsync("scrollInParentByClass", parent, className); } } }
/// <summary> /// Scrolls inside the given element to the given Y position. /// </summary> /// <param name="elementReference">Blazor reference to an HTML element</param> /// <param name="yPos">Scroll Y position</param> /// <returns>Async Task</returns> public static async Task ScrollToYAsync(this ElementReference elementReference, double yPos) { await using (var module = await elementReference.GetJsObject()) { if (module is not null) { await module.InvokeVoidAsync("scrollToY", elementReference, yPos); } } }
/// <summary> /// Scrolls inside the given parent element to the given inner element. /// </summary> /// <param name="parent">Blazor reference to an HTML (outer/wrapper) element</param> /// <param name="innerElement">Blazor reference to an inner HTML element to scroll to</param> /// <returns>Async Task</returns> public static async Task ScrollToElementInParentAsync(this ElementReference parent, ElementReference innerElement) { await using (var module = await parent.GetJsObject()) { if (module is not null) { await module.InvokeVoidAsync("scrollToElementInParent", parent, innerElement); } } }
/// <summary> /// Returns given element is above of the view port. /// </summary> /// <param name="elementReference">Blazor reference to an HTML element</param> /// <returns>Async Task</returns> public static async Task <bool> IsElementHiddenAboveAsync(this ElementReference elementReference) { await using (var module = await elementReference.GetJsObject()) { if (module is not null) { return(await module.InvokeAsync <bool>("isElementHiddenAbove", elementReference)); } } return(false); }
/// <summary> /// Returns given element scroll X position. /// </summary> /// <param name="elementReference">Blazor reference to an HTML element</param> /// <returns>Async Task with X pos</returns> public static async Task <double> GetScrollXPositionAsync(this ElementReference elementReference) { await using (var module = await elementReference.GetJsObject()) { if (module is not null) { return(await module.InvokeAsync <double>("getScrollXPosition", elementReference)); } } return(0); }
/// <summary> /// Copies the given element text content to clipboard. /// </summary> /// <param name="elementReference">ElementReference to get text</param> /// <returns>Async Task</returns> public static async Task <bool> CopyElementTextToClipboardAsync(this ElementReference elementReference) { await using (var module = await elementReference.GetJsObject()) { if (module is not null) { return(await module.InvokeAsync <bool>("copyElementTextToClipboard", elementReference)); } } return(false); }
/// <summary> /// Returns the given HTML element ClintBoundRect data. /// </summary> /// <param name="elementReference">Blazor reference to an HTML element</param> /// <returns>Async Task with <see cref="DomRect"/> value</returns> public static async Task <DomRect> GetClientRectAsync(this ElementReference elementReference) { await using (var module = await elementReference.GetJsObject()) { if (module is not null) { return(await module.InvokeAsync <DomRect>("getBoundingClientRect", elementReference)); } } return(new DomRect()); }