Dropdown materialize does not recognize click on smartphone in Chrome browser

Asked

Viewed 155 times

2

I have a table that has a materialize dropdown, which when selected by PC/Notebook works normally. But when clicked by some mobile device with the same browser it does not recognize touch as click and does not direct to the specific page. Code of <th> from the table below.

    <th>
        <!-- Dropdown Trigger -->
        <a class='dropdown-trigger btn' href='#' data-target='status'>Status</a>

        <!-- Dropdown Structure -->
        <ul id='status' class='dropdown-content'>
              <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Não Iniciado"})">Não Iniciado</a></li>
              <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Em Andamento"})">Em Andamento</a></li>
              <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Pausado"})">Pausado</a></li>
              <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Finalizado"})">Finalizado</a></li>
        </ul>
   </th>

I’m using jquery to call dropdowns

$('.dropdown-trigger').dropdown();
  • 1

    Tried @Html.Actionlink() instead of @Url.Action()?

1 answer

0

Try to do this:

Html:

<div>
    <!-- Dropdown Trigger -->
    <div class='btn'>
        <a id="dropdown-trigger" data-target="status" onclick="abreDropdown"> 
            Status
        </a>
    </div>

    <!-- Dropdown Structure -->
    <ul id='status' class='dropdown-content'>
          <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Não Iniciado"})">Não Iniciado</a></li>
          <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Em Andamento"})">Em Andamento</a></li>
          <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Pausado"})">Pausado</a></li>
          <li><a href="@Url.Action("Filtrar","Construcao", new {text = "Finalizado"})">Finalizado</a></li>
    </ul>

Javascript:

document.addEventListener('DOMContentLoaded', function() {
  let elem = document.getElementById('dropdown-trigger');
  let instances = M.Dropdown.init(elem);
});

function abreDropdown(){
    let elem = document.getElementById('dropdown-trigger')
    M.Sidenav.getInstance(elem).open();
}

I had a similar problem with Materialize and Angular, where the system ignored the link and insisted on trying to open a new page.

  • 1

    Hello, in case the problem is in the click of <li> and not in opening the dropdown itself. It’s like @Url.Action doesn’t run the link when there’s a touch on a mobile device.

  • @Thiagomoreira what happens if you replace the tag <ul> by a <div> with the same properties and direct leave the anchor (<a>) in place of <li>?

  • 1

    So I need the <tr> because it’s a table. this dropdown is inside a table so I can’t change

Browser other questions tagged

You are not signed in. Login or sign up in order to post.