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

197
Visualizações
How to add attribute to parent div with ClassName in ReactJS?

I'm using ReactJS material UI tabs navigation. I want to add one attribute named tabindex in one div with class=MuiTabs-flexContainer MuiTabs-centered having value -1 to its child nodes. I had tried but tabindex=-1 is getting added to somewhere else:

Here in this screenshot, I need tabindex=-1 in its child nodes i.e., button elements:

enter image description here

Here is the UI tabs part:

<Tabs value={value} id="tabSec">
  <Tab
    label={
      <span className={value === 0 ? "active-tab" : "custom-style-on-tab"}>
        ABC
      </span>
    }
  />

  <Tab
    label={
      <span className={value === 1 ? "active-tab" : "custom-style-on-tab"}>
        XYZ
      </span>
    }
  />
</Tabs>;

The function which I have done so far is:

const tabRoving = (element) => {
    element.addEventListener("keydown", function (e) {
      if (e.keyCode === 13) {
        if (element.contains(document.activeElement)) {
          element.childNodes.forEach(function (childElement) {
            if (childElement != document.activeElement) {
              childElement.setAttribute("tabindex", "-1");
              console.log("done");
            } else childElement.setAttribute("tabindex", "0");
          });
        }
      }
    });
  };

  useEffect(() => {
    tabRoving(document.getElementById("tabSec"));
  }, []);

How can I achieve this? Is this possible in ReactJS with material UI?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Have you tried passing a tabIndex={-1} prop on the Tab component? It should spread unused props down, eventually to the button.

Inheritance

While not explicitly documented above, the props of the ButtonBase component are also available on Tab. You can take advantage of this to target nested components.

Spread

Props supplied to a component which are not explicitly documented are spread to the root element; for instance, the className prop is applied to the root.

Pass a tabIndex prop to the Tab components:

<Tabs value={value} id="tabSec">
  <Tab
    tabIndex={-1}
    label={
      <span className={value === 0 ? "active-tab" : "custom-style-on-tab"}>
        ABC
      </span>
    }
  />

  <Tab
    tabIndex={-1}
    label={
      <span className={value === 1 ? "active-tab" : "custom-style-on-tab"}>
        XYZ
      </span>
    }
  />
</Tabs>
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