Why material select clones the select element class list?
See original GitHub issueConsidering a select element:
<select class="my-select">
<!-- options -->
</select>
After initialized by material_select
method the select class list is cloned in parent node:
<div class="select-wrapper my-select">
<!-- (...) -->
<select class="my-select">
<!-- options -->
</select>
</div>
Now the query selector .my-select
I will get div.my-select
instead of select.my-select
and it is does not seem the right thing.
For example, considering a scenario that has a handler for registration and upgrade new components and each component is represented by its class. This behavior breaks the normal flow of application.
Every time the handler check for upgrade it will double the components infinitely.
e.g.
<select class="my-select">...</select>
// Registration.
handler.registerComponent({
name: 'MySelect',
cssClass: 'my-select'
});
// Handler will query for the css class and upgrade all elements.
// First time, will upgrade ok because ".my-select" means the select element.
handler.upgradeComponent('MySelect');
Now the select element seems like this and handler knows that component is upgraded.
<div class="select-wrapper my-select">
<!-- (...) -->
<select class="my-select" data-upgraded="MySelect">
<!-- options -->
</select>
</div>
After, It will fail if need to check for upgrade:
// Now the handler will find "div.select-wrapper.my-select" instead of select element.
handler.upgradeComponent('MySelect');
<div class="select-wrapper my-select">
<!-- (...) -->
<div class="select-wrapper my-select" data-upgraded="MySelect">
<!-- (...) -->
<select class="my-select" data-upgraded="MySelect">
<!-- options -->
</select>
</div>
</div>
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Unable to clone angular material element using md-select
I used jquery for cloning the <tr> tags. Html Code <tr class="tr_clone"> <td> < ...
Read more >Element.classList - Web APIs | MDN
The Element.classList is a read-only property that returns a live DOMTokenList collection of the class attributes of the element.
Read more >MDC-111 Web: Incorporating Material Components into your ...
Learn how to incorporate individual Material Components into an existing web code base without starting over. ... Button; Select; Text field ...
Read more >5. Working with the Shadow DOM - Modern JavaScript [Book]
Creating a shadow root is a straightforward process. First a shadow host node is selected, and then a shadow root is created in...
Read more >Choices-js/Choices: A vanilla JS customisable select box/text ...
A vanilla, lightweight (~19kb gzipped ), configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found myself needing to replace the parent
'select-wrapper'
, with a newly cloned select element and after that run.material_select()
.else, I would get a
'select-wrapper'
inside another'select-wrapper'
much like:This makes me want to use the
browser-default
class on the select elements instead.Closed due inactivity, feel free to reopen it if it is still necessary.