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.

mdc-select with preselection in Aurelia

See original GitHub issue

I’ve a question about the mdc-select component. We’re using Aurelia for binding purposes with the mdc components. With the normal HTML5 approach, we can use this:

<select value.bind="selectedPersonID" class="mdc-select mdc-list-item__end-detail">
  <option model.bind="null">Select person</option>
  <option repeat.for="person of Persons" model.bind="person.ID">${person.Name}</option>
</select>

We’ve only the “selected item” as PersonID available. This approach works with the “init” (it shows the selected person with the name).

With mdc-select, the approach is a little different because there is a span. The next code is for the mdc-select.

<div mdc-select role="listbox" class="mdc-select mdc-list-item__end-detail">
  <span class="mdc-select__selected-text">????</span>
  <div class="mdc-simple-menu mdc-select__menu">
    <ul class="mdc-list mdc-simple-menu__items">
      <li class="mdc-list-item" role="option" repeat.for="person of Persons" model.bind="person.ID">${person.Name}</li>
    </ul>
  </div>
</div>

We’ve got a “selectedPersonId” for the selected person. I can also put the aria-selected property on the right “li-tag” (not in the code). That works like a charm when clicking the list open (it’s selected). But on init it won’t show on the question marks.

My question is: How can i preselect an item in the mdc-select with only the “PersonId” available, so that the span is also filled with the chosen Person.Name. Is it possible to dynamically change the “span” tag with the chosen aria-selected or something?

Thanks a lot! Keep up the good work!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
yeelan0319commented, Aug 3, 2017

I am going to close this issue since it is no longer a MDC question, but feel free to paste the answer in the following thread. @jordyboytjuh

1reaction
teoxoycommented, Jul 26, 2017

You can do it using the MDCSelect object in js. At the end of the function attached() you should set the property selectedIndex to the index you want. Example: this.mdcSelect.selectedIndex = index;

Read more comments on GitHub >

github_iconTop Results From Across the Web

@aurelia-mdc-web/select - npm
Start using @aurelia-mdc-web/select in your project by running `npm i @aurelia-mdc-web/select`. There are 3 other projects in the npm registry using ...
Read more >
@material/select NPM | npm.io
MDC Select provides Material Design single-option select menus. It functions as a wrapper around the browser's native <select> element.
Read more >
Select Menus - Material Design
MDC Select provides Material Design single-option select menus, using the MDC menu. ... To indicate a select component that has a pre-selected value, ......
Read more >
How to use mdc-select (Material design components) in ...
At this moment I'm working on a project where we use Aurelia in combination with Material Design Components. Because the project is fairly ......
Read more >
CHANGELOG_ARCHIVE.md - material-components-web
The change event is now MDCSelect:change for all variants. ... select: Fix floating label for pre-selected option (#2306) (d8dae34) ...
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