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

fix(TextArea): autoResize issue with v-show by implementing ResizeObserver #6630

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

KumJungMin
Copy link
Contributor

Defect Fixes


Resolution

Cause

  • When v-show is applied to a parent element, the height of the TextArea is not automatically adjusted.
  • This happens because the TextArea component does not detect visibility changes.
  • The updated hook in the TextArea is only triggered by changes in its reactive data or props, and it doesn't respond to the parent’s v-show changes.

Solution

  • To address this, I implemented ResizeObserver.
  • ResizeObserver detects size changes in elements and can also respond to visibility changes caused by the parent’s v-show.
  • This ensures that the TextArea automatically adjusts its height when the parent’s visibility changes.

Test

test sample code
<template>
    <span v-show="value.display === true">
        <div>
            <Textarea id="xxx" v-model="value.text" autoResize rows="1" cols="30" />
        </div>
    </span>
</template>

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

const value = ref({ text: '', display: false });

setTimeout(() => {
    value.value.text = 'fsdfsdfsd dsfsdgsdd gsdfsdg  sdgsdgsdgsd  sgdsdfgsdg sdgsdgsd sdgsdfgs gsdgsdg sdgsdgsdgsd gsdsdgsdg';
}, 50);

setTimeout(() => {
    value.value.display = true;
    console.log('display');
}, 1000);
</script>

before: AutoResize is not working when v-show is set to true

2024-10-23.9.54.03.mov

after: AutoResize is working when v-show is set to true_

2024-10-23.9.54.37.mov

- Problem: When using v-show to toggle the visibility of the Textarea component, the auto-resize functionality fails because this.$el.offsetParent returns null when the element is hidden.
- Solution: Added a ResizeObserver to detect size changes and adjusted the resize logic to handle visibility changes. Now, the Textarea component correctly auto-resizes when it becomes visible and when its content or parent size changes.
Copy link

vercel bot commented Oct 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
primevue ⬜️ Ignored (Inspect) Visit Preview Oct 23, 2024 0:59am
primevue-v3 ⬜️ Ignored (Inspect) Visit Preview Oct 23, 2024 0:59am

@fotisskal
Copy link

hello @KumJungMin ! do you have any estimation when this will be merged to master?

@KumJungMin
Copy link
Contributor Author

@fotisskal I'm sorry, but I’m unable to estimate a specific timeline for the merge :(

@tugcekucukoglu tugcekucukoglu merged commit aa92d01 into primefaces:master Nov 13, 2024
3 of 4 checks passed
@KumJungMin KumJungMin deleted the fix/issue-4510 branch November 15, 2024 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Textarea: AutoResize not working if the value is changed while textarea is not visible
3 participants