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

175
Visualizações
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 Respostas
Responde à pergunta

0

Could this be done more easily with CSS?

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

about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório

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 Relatório
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