Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
onKeyPress devuelve e.target.checked como falso

Tengo un componente de casilla de verificación con función onClick y función onKeyPress

El onCLick funciona bien. pero mi onKeyPress hace algunos problemas.

Cuando presiono la barra espaciadora, obtengo un evento onKeyPress que devuelve e.target.checked como verdadero -

ingrese la descripción de la imagen aquí

Pero cuando presiono enter obtengo e.target.checked como falso -

ingrese la descripción de la imagen aquí

Mi componente bastante sencillo:

 import React, { forwardRef, useEffect, useState } from "react"; import Root from "./CustomRadioButton.style"; import PropTypes from "prop-types"; const CustomRadioButton = forwardRef((props, ref) => { const { name, label, className, id, onClick, register, onChange, defaultChecked, ariaRequired } = props; useEffect(() => { console.log(checked); }, [checked]) const [checked, setChecked] = useState(""); const hadnleClick = (e) => { return setChecked(e.target.value); }; const hadnleKeyPress = (e) => { console.log(e); if (e.code == "NumpadEnter") { e.preventDefault(); return setChecked(e.target.checked); } } return ( <Root.Wrapper className={className} onClick={onClick} onKeyPress={hadnleKeyPress} > <input type="radio" name={name} id={id} onClick={hadnleClick} value={checked && checked} onChange={onChange} aria-required={ariaRequired} defaultChecked={defaultChecked} {...register} /> <label htmlFor={id}>{label}</label> </Root.Wrapper> ); }); CustomRadioButton.propTypes = { /** * ariaRequired */ ariaRequired: PropTypes.bool, }; CustomRadioButton.defaultProps = { ariaRequired: true }; export default CustomRadioButton;

donde esta mi error

ACTUALIZAR

Moví onkeypress a la entrada todavía no funciona

agregue mi css mayde es el problema

 input[type="radio"]:focus + label::before { border :1px solid black; } input[type="radio"]:checked + label::before { animation: ${checkedAnimtion} 250ms ease-out; background: #3cbfed; box-shadow: inset 0 0 0 5.5px #fdfdff; }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!