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

172
Vistas
How to get aria-current in React

There is this property, aria-current in a NavLink, it is set is set to value page (aria-current="page" for the selected element).

Is there a way to access it in React? In order to change the styling for the other links which aren't selected.

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

0

Could this be done more easily with CSS?

.navLink:not([aria-current]) { color: red;}

about 4 years ago · Juan Pablo Isaza Denunciar

0

See below, this is what I do with styled components with react router v6. But you can follow the same way of doing things with any other styling strategy.

const StyledNavLink = styled(NavLink)`
  text-decoration: ${(props) => {
    console.log(props.style);
    return props.style ? (isActive) => (isActive ? "underline" : "none") : "none";
  }};
  &:hover {
    text-decoration: underline;
  }
 &[aria-current] {
    color: red;
  }
`;

Or, as shown below, one can check for existence of the active class

const StyledNavLink = styled(NavLink)`
    text-decoration: ${(props) => {
    console.log(props);
    return props.style ? (isActive) => (isActive ? "underline" : "none") : "none";
  }}; 
  &:hover {
    text-decoration: underline;
  }
 &[class*="active"] {
    color: red;
  }
`;
about 4 years ago · Juan Pablo Isaza Denunciar

0

Yup you can access it via a ref of the element. For example:

const navRef = useRef(null);


...

return <nav ref={navRef}>{navRef.current.ariaCurrent}</nav>

Just a heads up: Attributes that start with aria are only intended for accessibility purposes so I wouldn't rely on them for the styling of components.

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