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: AutoResize not working if the value is changed while textarea is not visible #4510

Closed
jozefnad opened this issue Sep 27, 2023 · 4 comments · Fixed by #6630
Closed
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@jozefnad
Copy link

Describe the bug

Autoresizing of the TextArea does not function correctly under two specific conditions:

When the TextArea is displayed after its value has been assigned, the autoresize feature fails to work as expected.

If the TextArea is located outside the viewport and its content is programmatically changed, the resizing behavior does not function correctly.

To illustrate this issue, consider the following example:

https://stackblitz.com/edit/gvf5ux?file=src%2FApp.vue

<template>
  <div class="card flex justify-content-center">
    <span v-show="show === true" class="w-20rem">
      <Textarea id="xxx" v-model="text" autoResize rows="1" class="w-full" />
    </span>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const show = ref(false);

const text = ref(`fsdfsdfsd dsfsdgsdd 
  gsdfsdg  sdgsdgsdgsd  
  sgdsdfgsdg sdgsdgsd 
  sdgsdfgs gsdgsdg 
  sdgsdgsdgsd gsdsdgsdg`);

setTimeout(() => {
  show.value = true;
}, 10);
</script>

Reproducer

https://stackblitz.com/edit/gvf5ux?file=src%2FApp.vue

PrimeVue version

3.34.1

Vue version

3.x

Language

TypeScript

Build / Runtime

Vue CLI App

Browser(s)

No response

Steps to reproduce the behavior

  1. assign text value to textarea, which is hidden
  2. make textarea visible

Expected behavior

I expect the autoresize functionality of the textarea to work correctly as soon as it is displayed or changed.

@jozefnad jozefnad added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 27, 2023
@jozefnad
Copy link
Author

jozefnad commented Oct 2, 2023

You can add visibility observer for that component, so when it will be visible it will resize

const component= ref(null)
onMounted(() => {
  if(!component.value){return}

  const element = component.value
  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.intersectionRatio > 0) {
        resize()
      }
    });
  });
  observer.observe(element);
})

@tugcekucukoglu tugcekucukoglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Nov 16, 2023
@drien
Copy link

drien commented Mar 2, 2024

In case it's helpful to anyone else encountering this, I worked around it with a quick and dirty hack to the toggle method that revealed the textarea...adding and removing a single space character from the contents of the textarea triggers it to resize properly:

async toggleNotes() {
  this.notesVisible = !this.notesVisible;

  await nextTick();
  this.notes += ' ';

  await nextTick();
  this.notes = this.notes.slice(0, -1);
}

@fafeitsch
Copy link

This bug seems also to be present in version 4.0.3.

I had to use a similar workaround as drien, but I the nextTicks() didn't work in my case, so I had to resort to setTimeouts with 500ms delay to apply the hack.

@fotisskal
Copy link

Hello, any update regarding this? Do you have maybe an estimation when the fix will be added to the next version?

@tugcekucukoglu tugcekucukoglu added this to the 4.2.2 milestone Nov 13, 2024
tugcekucukoglu added a commit that referenced this issue Nov 13, 2024
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

Successfully merging a pull request may close this issue.

5 participants