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

150
Visualizações
Delete long text in TagInput

I have TagsInput where the user can enter any data (assumed to be links). Since links can be very long, I need a way to shorten their display so that the window does not stretch too much. I solved it with white-space: nowrap

Since I'm using TagsInput, the user should be able to delete the input. I have this functionality. And as you can see, it works on short links. But if the link is long, this cross is at the end and, accordingly, it is not visible. I would like everything to be displayed as follows (I marked the desired functionality in red):

Thus, I want the user to be able to delete a long link

.tag {
    display:flexbox;
    /* align-items: center; */
    margin: 5px 0;
    margin-right: 5px;
    padding: 0 5px;
    border: 1px solid black;
    border-radius: 5px;
    color: black;
    overflow:hidden;
    text-overflow: ellipsis;
    max-width: fit-content;
    white-space: nowrap;
}

Just in case, the part of the code where I define the button to remove the tag

...
    const deleteTag = (index) => {
    setTags(prevState => prevState.filter((tag, i) => i !== index))
}

return (
    <div className={classes.container}>
        {tags.map((tag, index) => <div className={classes.tag}>
            {tag}
            <ClearIcon className={classes.del} fontSize="small" onClick={() => deleteTag(index)} />
        </div>
        )}
        <input
            className={classes.input}
            value={input}
            placeholder={props.inputPlaceholder}
            onKeyDown={onKeyDown}
            onKeyUp={onKeyUp}
            onChange={onChange}
        />
    </div>);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you try to make it simple then you need to restructure your JSX:

<div className="tag">
  <div className="tag-name">www.google.com/dummytext/123</div>
  <ClearIcon className={classes.del} fontSize="small" onClick={() =>deleteTag(index)} />
</div>

CSS:

.tag {
  display: flex;
  border: 1px solid black;
  border-radius: 5px;
  padding: 0 5px;
  max-width: fit-content;
  margin: 5px 0;
}

.tag-name {
  margin-right: 5px;
  color: black;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: -moz-fit-content;
  max-width: fit-content;
  white-space: nowrap;
}
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