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] Dynamically loaded menu item values can't be set programmatically

See original GitHub issue

Using MDC 5.0.0 JS lib. Created a fiddle of what I’m seeing here: https://jsfiddle.net/jamauss/bdfcanh9/50/

It seems like if all menu items (<li> elements) are present at the time the MDC Select is created, setting the .value property works just fine.

However, if menu items are added afterwards (e.g. json data loaded via ajax call inserting menu items into the DOM), setting the .value property will not cause the items to be set in the list, despite the MDCSelect:change event firing, which seems to indicate the component knows the value is being set. What is interesting is if I set the .selectedIndex property instead, then it will set the item in the list correctly (even if loaded dynamically), but not if I set the .value property. Again, this seems to only apply to menu items loaded/appended after the MDCSelect is created.

Steps to reproduce

see https://jsfiddle.net/jamauss/bdfcanh9/50/

Actual behavior

Item is not being set in the list / no change occurring for what .value is being set to

Expected behavior

Have item in the list get set when the .value property is set

Software Version(s)
MDC Web 5.0.0
Browser Chrome 78
Operating System Win 10

Additional context

This occured after upgrading from a early version of the MDC JS lib (0.48) to 5.0.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Pupixcommented, Feb 26, 2020

I have encountered this problem too. Even using selectedIndex creates problems if the select items change. When you change the index it will try to remove the old --selected class but the items doesn’t exist anymore and it throws.

https://github.com/material-components/material-components-web/blob/master/packages/mdc-select/component.ts#L313

0reactions
allan-chencommented, Apr 23, 2020

@GoldenSlam sorry for the late reply. As you might have seen an overhaul of the select component is beginning to roll in, to yield some much needed quality of life improvements. We’ll get to this issue very soon as we polish this component up from the foundation layers and bridge some much needed feature gaps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mdc-select update hidden input value on change (non-native ...
I need to set/update the value of a hidden input on MDCSelect change for multiple select boxes on the same page.
Read more >
packages/mdc-select/README.md · Gitee 极速下载/material ...
MDC Select provides Material Design single-option select menus, using the MDC menu. The Select component is fully accessible, and supports RTL rendering.
Read more >
dynamically set menu items width to percentage ... - MSDN
dynamically set menu items width to percentage programmatically RRS feed ... I feel like I'm missing one little switch or something, but I...
Read more >
Element.scrollLeft - Web APIs | MDN
Element.scrollLeft · If the element can't be scrolled (e.g., it has no overflow), scrollLeft is set to 0 . · If specified as...
Read more >
Spring Boot Reference Documentation
Starter for using Redis key-value data store with Spring Data Redis and the ... activated in .spring-boot-devtools.properties will not affect the loading of ......
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