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

208
Visualizações
Change table background color when checkbox is ticked

I have this render:

render() {
    const {policy} = this.props;
    return (
      <div className="my-content">
          <table className="checkbox-table">
              <label>
                <input className="checkbox-round" type="checkbox" onClick={this.onClickOfAgreement(pol)}/>
                &nbsp;&nbsp; Agree and access
              </label>
          </table>
      </div>   

This is the CSS I'm using:

.my-content {
  position: relative;
  background-color: #fefefe;
  padding: 0;
}

.checkbox-table {
  margin: 10px;
  border-radius: 7px;
  width: auto;
  padding: 10px;
}

.checkbox-round {
  width: 1.3em;
  height: 1.3em;
  background-color: white;
  border-radius: 50%;
  vertical-align: middle;
  border: 1px solid grey;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
}

.checkbox-round:checked {
  background-color: #4f9f31;
  border-color: #fefefe;
  border-width: 3px;
}

I'd like the entire table background to also turn #4f9f31 when the checkbox is ticked. How is this done?

I tried the solution in Property 'value' does not exist on type 'Readonly<{}>' but caused this error in my browser:

Property 'backgroundColor' does not exist on type 'Readonly<{}>'

I added a State interface to resolve the error but then got TypeError: Cannot read properties of null (reading 'backgroundColor'). I seem to be missing something though. How to dynamically add a class to manual class names? but it give me

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

0

<table className={`checkbox-table ${this.state.addBackgroundColor}`}>

To make it work you you need to initialize a state called addBackgroundColor. Then, your fuction onClickOfAgreement(pol) can set the state backgroundColor to 'checked'. Then on CSS you make a rule that adds the background color when the state is checked:

.checked {
  background-color: #4f9f31;
}
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