Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
How to highlight the selected item from basic dropdownlist in ember?

I'm using a basic dropdown in Ember and in the list, once we select item in the content list, I want to highlight the selected item. I'd like to know if I can use a simple [aria-current] & [aria-selected] in CSS to make it happen.

hbs file:

{{#each pagelist as |page|}} 
   <li class=" dropdown-class" {{action "getAllPages" page dd.actions}}>
        <p {{page.name}}</p>
    </li>
{{/each}}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think the quickest way to get you highlighted "Something selected", would be to,

(using ember-source 3.25+) and: https://github.com/NullVoxPopuli/ember-functions-as-helper-polyfill/ (landing in ember-source 4.5~ish, polyfilled for 3.25+)

// app/components/my-component.js
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

export default class MyComponent extends Component {
  @tracked selectedIndex;

  select = (index) => this.selectedIndex = index;
  isSelected = (index) => this.selectedIndex === index;
}
{{!-- app/component/my-component.hbs --}}
{{!-- where does pagelist come from? - let's assume it's passed in --}}

<ul>
  {{#each @pagelist as |page index|}} 
    <li 
      class="dropdown-class {{if (this.isSelected index) 'highlighted'}}" 
      {{on "click" (fn this.select index)}}
    >
      <p>{{page.name}}</p>
    </li>
  {{/each}}
</ul>

Note though, that it's an accessibility violation to make <li> clickable (and ember-template-lint would give you an error), so you'll probably want a button in the li instead:

<li class="dropdown-class {{if (this.isSelected index) 'highlighted'}}">
  <button type="button" {{on "click" (fn this.select index)}}>
    {{page.name}}
  <button>
</li>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!