In my current project, I have a scrollable area that highlights the selected div in gray. The HTML is written using Ember (hbs) and includes code to handle this functionality. Below is an example of how the div looks:
https://i.sstatic.net/T2Lur.png
Here is the corresponding HTML (hbs):
<div role="listbox" style="overflow-y: auto">
{{#each @variables as |var|}}
<div class="variable-row {{if (eq var @selectedVar) "selected-row"}}">
{{var}}
</div>
{{/each}}
</div>
Additionally, here is the CSS used to style the selected row:
.selected-row {
background-color: gray;
}
One issue I am facing is that when the selectedVar
is not visible within the scrollable area, such as when it is below other elements and needs to be scrolled into view. Is there a way to automatically scroll to the element with the selectedVar
? Perhaps by modifying the HTML structure or adding some CSS classes?
{{#each @variables as |var|}}
<div {{if (eq var @selectedVar) "scroll-to-this-element"}}>
{{var}}
</div>
{{/each}}