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.

Why material select clones the select element class list?

See original GitHub issue

Considering 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:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
ruinunescommented, Jun 21, 2017

I found myself needing to replace the parent 'select-wrapper', with a newly cloned select element and after that run .material_select().

$existingSelects.on 'contentChanged', ->
  $select = $ this
  $select.parent('.select-wrapper').replaceWith $select
   @$select.material_select()

else, I would get a 'select-wrapper' inside another 'select-wrapper' much like:

image

This makes me want to use the browser-default class on the select elements instead.

0reactions
fegacommented, May 6, 2017

Closed due inactivity, feel free to reopen it if it is still necessary.

Read more comments on GitHub >

github_iconTop 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 >

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