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

127
Vistas
React select Icon click

Hey Am using React select Custom component and In the dropdown Option am Adding 2 icons,and i want to add the onClick Event on that, the Problem is when i click the icon, the default onClick also get called and the default action also get executed in the background.

export const SvdSrchSelectOpt = (props : any) =>
{
  return (
    <components.Option {...props} >
      <Styld.Div >
        <div className="flex-auto w-full">{props.label}</div>
        <div className="container flex ml-auto justify-end">
          <Button variant='noBorder' onClick={props.onEdit} icon="writing-editing" className='max-w-35p justify-items-center'>
          </Button>
          <Button variant='noBorder' onClick={props.onDelete} icon="TrashMessaging" className='max-w-35p justify-items-center'>
          </Button>
        </div>
      </Styld.Div>
    </components.Option >
  );
};

i want if user Click on the Label then default onClick get execute but if user click on any of these icon then icon's Onclick get execute. Please help me in this Thanks In Advance

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

0

The easiest way is to use event.stopPropagation inside the Icons functions. So something like:

function onEdit(event) => {
  event.stopPropagation();
  ...

But this means you won't be able to to catch the click anywhere else (for example you might have an open selector you might want to close when the page is clicked or something similar). Another pretty easy solution (and the option I would personally recommend) would be replacing e.stopPropagation() with e.preventDefault() + e.defaultPrevented

So basically you should add inside icons functions:

function onEdit(event) => {
  event.preventDefault();
  ...

and default onClick should have the condition. Something like:

function onClick(event) => {
  if(event.defaultPrevented) return
}

You can also see more about this topic here

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