ngx-autosize icon indicating copy to clipboard operation
ngx-autosize copied to clipboard

wrong emitted height in components with ChangeDetectionStrategy.OnPush

Open capc0 opened this issue 4 years ago • 6 comments

If this plugin is used within components that have the OnPush change detection strategy, the initial height is incorrect.

My guess is that the height of the clone (https://github.com/chrum/ngx-autosize/blob/master/projects/autosize/src/lib/autosize.directive.ts#L148) is not correct. A possible fix could be to run https://angular.io/api/core/ChangeDetectorRef#detectChanges or wrap the code in a setTimeout.

capc0 avatar Aug 12 '20 07:08 capc0

sweet :) i just reproduced it, great finding!

chrum avatar Aug 16 '20 18:08 chrum

hey @capc0

Its a bit difficult to crack the problem. I noticed that its not really the thing with onPush strategy but with textarea packed in a component that receives value through inputs... its also problematic when textarea gets autosized immediately after app starts...

...anyway :) i fixed what i was able to reproduce (all described above) so check 'next' channel please: npm install ngx-autosize@next

if this doesnt help then can you do me a favor and put some example repo with the bug?

chrum avatar Aug 18 '20 16:08 chrum

hi thanks for your feedback. unfortunately the @next version did not fix the problem for me. I will try to provide you a example repo within the next few days :)

capc0 avatar Aug 19 '20 06:08 capc0

Issue is reproducable here: https://stackblitz.com/edit/angular-jxkwwz?file=src/app/textarea-input/textarea-input.component.html

If you load the page, it shows 5 lines

image

Clicking inside the textarea and then somewhere else in the document again increases the height

image

But it seems to be related to bootstrap, since If I remove the imports in the index.html it looks OK.

capc0 avatar Aug 19 '20 13:08 capc0

Same issue :) Didn't get initial height. Need to focus in field to have correct size. More information: This occur mainly when field is hidden when page is loaded. I receive onResize event with value "NaN". Here is my workaround: image

gilsdav avatar Feb 17 '21 19:02 gilsdav

Hi, I am facing the same issue any updates on this?

sarahmarciano1 avatar Jan 23 '23 11:01 sarahmarciano1