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

135
Visualizações
Change scrollHeight of other component

I have component like this:

const Panel = () => {
  const input = useRef<HTMLTextAreaElement>(null);

  return (
    <Wrapper>
      <Input
        ref={input}
      />
        <Button
          onClick={() => {
            input.current?.scrollHeight = "";
          }}
        >
        </Button>
    </Wrapper>
  );
};

I need to change the Input's scrollHeight on Button click, so I tried to use useRef, but I get an error: Cannot assign to 'scrollHeight' because it is a read-only property. How can I fix it?

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

0

I don't have a lot to go off of, from what you've written, but something like this might help:

const Panel = () => {
  const input = useRef<HTMLTextAreaElement>(null);
   // collect the current style height that is used to establish the scroll height
  const height = document.getElementyById()?.clientHeight

  return (
    <Wrapper>
      <Input
        ref={input}
      />
        <Button
          onClick={() => {
             function (){
                document.getElementById()?.style.height = `${height}px`;
              }} 
        > // add to the height this way, start with the clientheight and add to it
        </Button>
    </Wrapper>
  );
};
about 4 years ago · Juan Pablo Isaza Relatório

0

As per the docs

The Element.scrollHeight read-only property is a measurement of the height of an element's content, including content not visible on the screen due to overflow. https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight

Depending on what you want to achieve, you may want to use window.pageYOffset || document.documentElement.scrollTop to measure element's distance from the top, or manipulate one of the getBoundingClientRect() properties.

Or perhaps if you just want to reduce the elements dimensions, you may want to set fixed height and set overflow to scroll.

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