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

120
Visualizações
Changing the onClick function of a DOM element in React

I have an accordion like structure but for tabs in a menu.

Each tab has an arrow which moves up and down depending on whether the tab is expanded or condensed.

My code:

export default class Tab extends Component<TabProps> {
    tabRef: any;
    arrowRef: any;
    clickFunction: any;

    constructor(props: any) {
        super(props);
        this.tabRef = React.createRef();
        this.arrowRef = React.createRef();
        this.clickFunction = this.expand.bind(this);
    }

    expand() {
        this.arrowRef.current.style.animation = '0.3s rotateArrowDown ease-in-out forwards';
        this.clickFunction = this.condense.bind(this);
    }

    condense() {
        this.arrowRef.current.style.animation = '0.3s rotateArrowUp ease-in-out forwards';
        this.clickFunction = this.expand.bind(this);
    }


    render() {
        const num = this.props.num;
        const desc = this.props.desc;
        const parts = this.props.parts;

        var subTabs = [];
        for(let i = 1; i <= parts.length; i++) {
            subTabs.push(<a className="sub-tab" href={parts[i - 1].link}>
                <span className="sub-tab-desc">{parts[i - 1].desc}</span>
            </a>)
        }

        return (
            <div className="menu-tab" ref={this.tabRef} onClick={this.clickFunction}>
                <div className="tab-title">
                    <div className="tab-arrow" ref={this.arrowRef}></div>
                    <div className="tab-num">{num}</div>
                    <div className="tab-desc">{desc}</div>
                </div>
                <div className="sub-tabs">
                    {subTabs}
                </div>
            </div>
        );
    }
};

But this does not work.

Is there a way to do this?

about 4 years ago · Santiago Trujillo
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