Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea does not auto resize its height when created #733

Closed
derMart opened this issue Dec 2, 2020 · 3 comments
Closed

Textarea does not auto resize its height when created #733

derMart opened this issue Dec 2, 2020 · 3 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@derMart
Copy link

derMart commented Dec 2, 2020

As title, create a Textarea with :autoResize=true and its model to contain some large text.
The Textarea will only adjust its height after the contents of the textarea dom element is changed by the user (so that its scrollheight is affected, e.g. by entering a newline)

Initially, this.cachedScrollHeight is falsy, so that it will be set to this.$el.scrollHeight by

this.cachedScrollHeight = this.$el.scrollHeight;

Then, the code block following:
if (this.cachedScrollHeight !== this.$el.scrollHeight) {

won't be executed, which results in the height of $el not being set to the scrollHeight.

The fix for this issue is simple, just remove:

this.cachedScrollHeight = this.$el.scrollHeight;

That way, the height of $el will be adjusted, as this.cachedScrollHeight !== this.$el.scrollHeight

@derMart derMart changed the title Textarea does not auto resize its height when created / mounted (and its model value exceeds its height) BUG (including fix): Textarea does not auto resize its height when created / mounted (and its model value exceeds its height) Dec 2, 2020
@fairking
Copy link

fairking commented Dec 9, 2020

Agree. I have the same issue. I am not sure but I thought it was working before.

@cagataycivici cagataycivici self-assigned this Dec 9, 2020
@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Dec 9, 2020
@cagataycivici cagataycivici added this to the 3.1.0 milestone Dec 9, 2020
@cagataycivici cagataycivici changed the title BUG (including fix): Textarea does not auto resize its height when created / mounted (and its model value exceeds its height) Textarea does not auto resize its height when created Dec 9, 2020
@cagataycivici
Copy link
Member

This was also in PrimeNG-PrimeReact so I've ported the solution from there to fix it.

@ilzbergs
Copy link

Can someone know to deal with this situation, when autoResize doesn't resize if text is larger that textArea field? Only resize on user typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

4 participants