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

297
Visualizações
Display Search icon inside search box , throws error in react

I was trying to add search icon inside search box here's my code so far :

 <div className='search'>
            <input
              id="quick_search"
              className="xs-hide"
              name="quick_search"
              placeholder="Search by creator, collectible or collection."
              type="text"
              onChange={(e) => {
                changeKey(e);
              }}
              onKeyDown={keyPress}
              value={keyword} 
              >
             <i class="fa fa-search" aria-hidden="true"></i>  
              </input>
          </div>

i face this Error: input is a void element tag and must neither have children nor use dangerouslySetInnerHTML.

can anyone help me with this ? much appreciated ! thanks

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

React's input element the same as HTML's input element can't have children.

You have to make the icon appear in the input box using CSS, you can't place it as a child.

.form-field {
  position: relative;
  display: inline-block;
}

.icon {
  position: absolute;
  right: 0;
}
<div class="form-field">
  <input>
  <span class="icon">🔍</span>
</div>

Also, you didn't close the <input> tag. It's wrong because every tag in react has to be closed either by using the closing tag </input> or using a self-closing tag <input />

You code should probably look like this:

<div className='search'>
  <input
    id="quick_search"
    className="xs-hide"
    name="quick_search"
    placeholder="Search by creator, collectible or collection."
    type="text"
    onChange={(e) => {
      changeKey(e);
    }}
    onKeyDown={keyPress}
    value={keyword}
  /> {/* <--- notice `/` here */}
  <i class="fa fa-search" aria-hidden="true"></i>
</div>
about 4 years ago · Santiago Trujillo 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