question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render a component at a specific position in the DOM

See original GitHub issue

As working with the DOM in Blazor has its limitations, what is the current recommendation for displaying popups like dialogs at specific positions on the page?

For example, showing a window/dialog on a button click inside a Blazor component requires the popup element to be appended to a specific element (let’s say the body) in order to be displayed over all other elements on the page. However, there is also the case for showing a popup inside another popup, so basically the position might be determined based on certain conditions.

One way to solve this might be to render a “special” element by using the idea of @(await Html.RenderComponentAsync<App>()) and then use JS interop to manually move elements from their original position to the desired one. However, this will probably break the diffing algorithm.

Are there any better ways to handle this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveSandersonMScommented, Jun 5, 2019

Oh wait I think I do understand you now. When talking about positions, you mean positions inside the DOM (like, which other element it’s nested inside), not the position it gets rendered to on the screen.

The initial feature set we’re going for is similar to other SPA frameworks. So for example if you wanted to render a tooltip that moves to whatever button the mouse is hovering over, you could either:

  • Have a <MyTooltip> inside each such button, with it being coded to render nothing by default, but render something visible when the mouse hovers over its parent (which itself could be achieved through CSS, or procedural logic with the parent issuing some state change when it gets a mouseover/mouseout event)
  • Or, render one global “tooltip” somewhere with display:none; position:absolute then use JS interop to move it around and change the visibility on demand.
0reactions
egilcommented, Jun 5, 2019

Stamo, if you cannot or do not want a component rendered behind a @if(condition) clause in each place it might show up, and if rendering it in one place and moving (or cloning/copying it) via JavaScript breaks the diff algo, the a third option could be to render the needed markup to screen using MarkupString class. That might render it as basic HTML that the diff algo doesn’t care about, and you can then move that around as you want with JavaScript.

@SteveSandersonMS can you tell us if the diff algo will break if we use JavaScript to add new HTML inside HTML generated by a component, if the added HTML doesn’t contain the “tracking comments” ()?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Self Positioning React Components
If you query an element on the DOM and call .getClientRects() it'll return an object of values with the position, height and width...
Read more >
React - Render component based on the position of other ...
The boxes and line is just an example. I'm asking how to have a React component render based on the DOM coordinates of...
Read more >
Render a component at a specific position in the DOM
One way to solve this might be to render a "special" element by using the idea of @(await Html.RenderComponentAsync<App>()) and then use JS ......
Read more >
How to change the position of the element dynamically in ...
Approach: We are going to use following steps: Assume the position of our element is 0 on x-coordinate and 0 on y-coordinate. Then...
Read more >
Self Positioning React Components | by Benjamin Schachter
In setStyles we query the DOM for a specific step rather than include the component multiple times. The container component renders the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found