materialize icon indicating copy to clipboard operation
materialize copied to clipboard

Dynamic dropdown-content generation with Angular5 throw a tabIndex null exception

Open d-mance opened this issue 8 years ago • 2 comments

When I generate dynamic content with different dropdowns the dropdown throws an error. If I do not generate dynamic dropdown content it works, the problem is with that generatiaon

Expected Behavior

Open a drop down

Current Behavior

It throws an error: Cannot set property 'tabIndex' of null

Steps to Reproduce (for bugs)

HTML

<div class="col s12 m12 l12 xl12 blue-grey lighten-1">
  <div id="instrumentStatus">
    <span class="right" *ngFor="let labSystem of nodeLabSystems">
      <a class="btn btn-flat dropdown-trigger" data-target="content-{{labSystem.system.name}}" id="{{labSystem.system.name}}"
        (click)="open(labSystem.system.name)">{{labSystem.system.name}}</a>
    </span>
  </div>
</div>
<ul id="content-{{labSystem.system.name}}" class="dropdown-content" *ngFor="let labSystem of nodeLabSystems">
  <li>
    <a href="#!">one</a>
  </li>
</ul>

Typescript

  open(dropdown): void {
    const elem = document.getElementById(dropdown);
    const instance = M.Dropdown.init(elem, {constrainWidth: true});
    instance.open();
  }

Context

I want to have a dropdown with revelant information about my items.

Your Environment

  • Version used: 1.0.0-rc.1
  • Browser Name and version: chrome 63
  • Operating System and version (desktop or mobile): ubuntu 16.04
  • Link to your project (if appropriate):

d-mance avatar May 28 '18 13:05 d-mance

Hi,

I had the same problem. In my case the data-target was not matching with the id of target element. You may check also if the dropdown is initializing after your html was already rendered.

thiagojsf avatar Jun 08 '18 20:06 thiagojsf

The same error appears when you call the Autocomplete plugin:

const autocomplete = M.Autocomplete.init(searchForm.querySelectorAll('input'));
<div class="search-bar-container">
	<form id="search-bar" action="#">

		<input name="q" type="search" class="autocomplete" required value="">
			
		<button type="submit" class="waves-effect tooltipped">
			<i class="center material-icons">search</i>
		</button>
	</form>
</div>

jhm-ciberman avatar Aug 05 '18 08:08 jhm-ciberman