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

95
Vistas
Track Cursor Location OnClick Phone/Dial Pad (React)

I'm trying to implement an on screen phone that takes input from either the keyboard, or from clicking on the numbers on screen.

enter image description here

The input field already works for key down implementations (typing 1 2 3 ....) naturally and where the cursor is (likely from .selectionStart). I'm having an impossible time tracking cursor position when I click on the on screen keyboard. I have tried quite a few different implementations but the current one is:

<input 
  type="text" 
  className="phone-pad-input" 
  id="phone-input"
  onChange={(e) => handleKeypress(e)}
  onFocus={(e) => {e.target.selectionStart = props.cursorPosition}} // coded this last week forget if it even works or does anything
  autoFocus={true} // I want the phone's input focused 100% of the time it's up
  autoComplete="off"
  onBlur={({ target }) => target.focus()}
  value={props.number}>
</input>

My screen key pad is a table where each number is:

<td className="..." onClick={() => handleKeyClicked(#)}></td>

Function for the handleKeyClicked:

const handleKeyClicked = (num: any) => {
  const phoneKeyPad = document.getElementById('phone-input')
  const cursorPosition = (phoneKeyPad as HTMLInputElement).selectionStart 
  console.info("CURSOR POS:", cursorPosition) // this is ALWAYS 0
  // ... logic to put my number in the correct spot with slicing based on cursorPosition
}

Is there any way to grab the .selectionStart from this onclick on the phone pad? If my value is: 1245 and I have my cursor (blinking) between the 2 and 4. I hit the "3" it still says cursor position is 0 and will either append or prepend depending how I coded it. I opened up Google Voice for the sake of testing their phone, and it also appends the numbers (12453) regardless of cursor position.

Thanks for any assistance

about 4 years ago · Juan Pablo Isaza
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