Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda