Component Interop Service
Low-level JS interop helpers for building custom components — scroll locking, focus traps, positioning, clipboard, and more.
Overview
The ComponentInteropService is the shared JS interop layer
used by all Lumeo components internally. If you are building custom overlay components, dropdown menus, or anything that needs
DOM interaction from C#, inject this service instead of calling IJSRuntime directly.
IAsyncDisposable.
Always handle JSDisconnectedException in cleanup methods
to avoid errors when the Blazor circuit disconnects.
Copy to Clipboard
Copy arbitrary text to the user's clipboard. Useful for code snippets, share links, API keys, and similar.
Try it: type something and copy it
Scroll to Top
Smooth-scroll the page back to the top. Useful for long pages, back-to-top buttons, or after navigation.
Try it: scroll down the page first, then click the button
File Download
Trigger a browser file download from a base64-encoded string. Works for any file type -- text, CSV, JSON, images, PDFs, etc.
Try it: download a sample file
Scroll Locking
Prevent background scrolling when a modal or overlay is open. Used internally by Dialog, Sheet, Drawer, and AlertDialog.
LockScroll()
twice, you must call UnlockScroll() twice to fully
restore scrolling. This prevents issues when multiple overlays are stacked.
Focus Management
Control keyboard focus for accessible overlay components. Focus trapping ensures that Tab and Shift+Tab cycle within a container element, which is required by WCAG for modal dialogs.
Focus Trapping
Focus a Specific Element
Used internally by: Dialog, AlertDialog, Sheet, Drawer, DropdownMenu, ContextMenu, Command, Select, Combobox.
Click Outside Detection
Detect clicks outside a specific element to auto-close dropdowns, popovers, and similar floating UI. Optionally exclude a trigger element so that clicking the trigger does not fire the handler.
Used internally by: Popover, DropdownMenu, Combobox, Select, DatePicker, NavigationMenu, HoverCard.
Element Positioning
Position a floating element (dropdown, tooltip, popover) relative to a reference element. Handles viewport boundaries, alignment, and optional width matching.
| Parameter | Type | Description |
|---|---|---|
| contentId | string | ID of the floating element to position |
| referenceId | string | ID of the anchor/trigger element |
| align | string | "start", "center", or "end" alignment |
| matchWidth | bool | Whether to match the reference element's width |
| side | string | "top", "bottom", "left", or "right" |
Used internally by: Tooltip, Popover, DropdownMenu, Select, Combobox, DatePicker, HoverCard, Menubar, NavigationMenu.
Element Measurement
Read element dimensions and positions from the DOM. Returns an
ElementRect record with X, Y, Width, and Height.
GetElementRect returns
null if the element is not found.
The dimension parameter accepts
"width", "height", "offsetWidth", "offsetHeight", "scrollWidth", "scrollHeight".
Advanced
These methods are used internally by specific Lumeo components. You typically do not need them unless building custom components with similar behavior.
Gestures
Touch and swipe gesture handling for mobile-friendly interactions.
Resize Handles
Drag-to-resize for resizable panel layouts. Used by the Resizable component.
Scrollspy
Track which section is currently visible during scroll for navigation highlighting.
Textarea Auto-Resize
Automatically grow a textarea element as the user types, up to a maximum number of rows.
OTP Paste Handling
Handle clipboard paste events on OTP (one-time password) input groups. Distributes pasted digits across individual input fields.
Affix (Sticky Elements)
Stick an element to the viewport when it would scroll out of view. Similar to CSS
position: sticky but with callback notifications.
Back to Top
Register a scroll listener that fires when the user scrolls past a threshold. Used to show/hide a back-to-top button.
Mention Caret Position
Get the visual caret position inside a textarea for positioning mention/autocomplete dropdowns.
DataGrid Column Resize
Drag-to-resize columns in a data grid. Similar to resize handles but specialized for table column headers.
Full API Reference
| Method | Category | Returns | Description |
|---|---|---|---|
| LockScroll() | Scroll |
ValueTask | Prevent page scrolling |
| UnlockScroll() | Scroll |
ValueTask | Re-enable page scrolling |
| ScrollToTop() | Scroll |
ValueTask | Smooth scroll to page top |
| SetupFocusTrap(elementId) | Focus |
ValueTask | Trap Tab focus within an element |
| RemoveFocusTrap(elementId) | Focus |
ValueTask | Remove focus trap from element |
| FocusElement(elementId) | Focus |
ValueTask | Focus a specific element by ID |
| FocusMenuItemByIndex(containerId, index) | Focus |
ValueTask | Focus the nth menu item in a container |
| GetMenuItemCount(containerId) | Focus |
ValueTask<int> | Count focusable menu items |
| RegisterClickOutside(elementId, triggerId?, handler) | Click |
ValueTask | Detect clicks outside an element |
| UnregisterClickOutside(elementId) | Click |
ValueTask | Stop detecting outside clicks |
| PositionFixed(contentId, refId, align, matchWidth, side) | Position |
ValueTask | Position floating element relative to reference |
| GetElementRect(elementId) | Measure |
ValueTask<ElementRect?> | Get bounding rect (X, Y, Width, Height) |
| GetElementRectBySelector(selector) | Measure |
ValueTask<ElementRect?> | Get rect by CSS selector |
| GetElementDimension(elementId, dimension) | Measure |
ValueTask<double> | Get a single dimension value |
| CopyToClipboard(text) | Clipboard |
ValueTask | Copy text to clipboard |
| DownloadFile(fileName, base64, mimeType?) | File |
ValueTask | Trigger browser file download |
| RegisterDrawerSwipe(elementId, handler) | Gesture |
ValueTask | Detect swipe-to-dismiss on drawer |
| UnregisterDrawerSwipe(elementId) | Gesture |
ValueTask | Remove drawer swipe handler |
| RegisterCarouselSwipe(elementId, orientation, swipe, scroll) | Gesture |
ValueTask | Handle swipe/scroll for carousel |
| UnregisterCarouselSwipe(elementId) | Gesture |
ValueTask | Remove carousel swipe handler |
| CarouselScrollTo(elementId, index, behavior?) | Gesture |
ValueTask | Scroll carousel to specific slide |
| RegisterResizeHandle(elementId, direction, resize, resizeEnd) | Resize |
ValueTask | Drag-to-resize for panels |
| UnregisterResizeHandle(elementId) | Resize |
ValueTask | Remove resize handler |
| RegisterScrollspy(containerId, offset, smooth, handler) | Scroll |
ValueTask | Track active section during scroll |
| UnregisterScrollspy(containerId) | Scroll |
ValueTask | Remove scrollspy listener |
| ScrollspyScrollTo(containerId, sectionId, smooth) | Scroll |
ValueTask | Scroll to a specific section |
| SetupAutoResize(elementId, maxRows) | Textarea |
ValueTask | Auto-resize textarea as user types |
| RegisterOtpPaste(baseId, length, handler) | Input |
ValueTask | Handle paste for OTP inputs |
| UnregisterOtpPaste(baseId, length) | Input |
ValueTask | Remove OTP paste handler |
| RegisterAffix(elementId, offsetTop, offsetBottom?, target?, handler) | Scroll |
ValueTask | Stick element to viewport on scroll |
| UnregisterAffix(elementId) | Scroll |
ValueTask | Remove affix handler |
| RegisterBackToTop(id, threshold, handler) | Scroll |
ValueTask | Track scroll position for back-to-top |
| UnregisterBackToTop(id) | Scroll |
ValueTask | Remove back-to-top listener |
| GetTextareaCaretPosition(elementId) | Input |
ValueTask<TextareaCaretInfo> | Get caret position for mention dropdowns |
| RegisterColumnResize(handleId, resizeHandler, resizeEndHandler) | Resize |
ValueTask | Drag-to-resize for data grid columns |
| UnregisterColumnResize(handleId) | Resize |
ValueTask | Remove column resize handler |
| RegisterToastSwipe(elementId, toastId, handler) | Gesture |
ValueTask | Swipe-to-dismiss for toast notifications |
| UnregisterToastSwipe(toastId, elementId) | Gesture |
ValueTask | Remove toast swipe handler |
Types
| Type | Properties | Description |
|---|---|---|
| ElementRect | double X, Y, Width, Height | Bounding rectangle returned by GetElementRect |
| TextareaCaretInfo | double Top, Left; int SelectionStart | Caret position info returned by GetTextareaCaretPosition |