Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
How to make cursor pointer while pointer-events is none

I have input type="text" associated with a datalist, and I want to add a fixed arrow (svg) in the input box so that when someone clicks it the datalist opens (as they clicked the box).
The problem is that the arrow I added has its default cursor-events so by default when I click it the datalist doesn't open.
I changed the cursor-events to none, the problem is solved but the cursor now is text, I want it to be pointer whenever mouse is over the arrow and text whenever mouse is over the box.
I tried the solution here: https://stackoverflow.com/a/25654479/7867670 but it didn't work for me
I tried to add an onclick event listener to the arrow and to trigger input click whenever the arrow is clicked, didn't work too.

input::-webkit-calendar-picker-indicator {
    display: none !important;
}

.wrapper{
    position: relative;
    display: inline;
    left: -25px;
    cursor: pointer;
}

.wrapper svg{
    pointer-events: none;
}
<input type="text" list="mylist" name="inp" />
<div class="wrapper" onclick="getElementsByName('inp')[0].click();">
    <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
        <path fill="currentColor" d="M16.293 9.293L12 13.586L7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z" />
    </svg>
</div>
<datalist id="mylist">
    <option value="1"></option>
    <option value="2"></option>
    <option value="3"></option>
</datalist>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As far as I know, this is not possible without JavaScript.

  1. The arrow can only change the cursor if it has pointer-events that is not none, but then the input won't get the click.

  2. input can't have children so that is also not an option.

  3. All of the search results indicate that the datalist can't be opened (reliably?) with JavaScript or html only solutions.

The only thing that comes to my mind is to change the cursor programmatically:

function isEventInElement(event, element) {
  var rect = element.getBoundingClientRect();
  var x = event.clientX;
  if (x < rect.left || x >= rect.right) return false;
  var y = event.clientY;
  if (y < rect.top || y >= rect.bottom) return false;
  return true;
}

const inputElement = document.querySelector('[name="inp"]')
const inputElementArrow = document.querySelector('.wrapper')

inputElement.addEventListener('mousemove', (evt) => {
  if (isEventInElement(evt, inputElementArrow)) {
    inputElement.style.cursor = 'pointer'
  } else {
    inputElement.style.cursor = null;
  }
})
input::-webkit-calendar-picker-indicator {
  display: none !important;
}

.wrapper {
  position: relative;
  display: inline;
  left: -25px;
  pointer-events: none;
}

.wrapper svg {}
<input type="text" list="mylist" name="inp" />
<div class="wrapper" onclick="getElementsByName('inp')[0].click();">
  <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
        <path fill="currentColor" d="M16.293 9.293L12 13.586L7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z" />
    </svg>
</div>
<datalist id="mylist">
    <option value="1"></option>
    <option value="2"></option>
    <option value="3"></option>
</datalist>

Code form other answers:

  • isEventInElement: Detect if a mouse event occurred inside an element's client area
about 4 years ago · Juan Pablo Isaza Denunciar

0

You would want to set the input's cursor via css. Preferably add a css class to the input cursor-pointer and create some css for that selector.

.cursor-pointer {
    cursor: pointer !important;
}

If I'm not mistaken, it sounds like you're not expecting the user to type in the input field but rather click it like a dropdown. If that's the case I would recommend using a button to trigger the list, if possible.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda