Skip to content

fix(autosize): not updating when window is resized #8619

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

Merged
merged 1 commit into from
Dec 8, 2017

Conversation

crisbeto
Copy link
Member

Fixes the autosize textarea not recalculating its height when the viewport size has changed.

Fixes #8610.

@crisbeto crisbeto requested a review from mmalerba as a code owner November 23, 2017 18:40
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 23, 2017
}
}

ngOnDestroy() {
this._resize.unsubscribe();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't we been switching to the _destoryed.next() style?


this._resize = this._ngZone.runOutsideAngular(() => {
return fromEvent(window, 'resize')
.pipe(debounceTime(10))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't auditTime be more appropriate here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. We want to prevent this from happening if we get a bunch of resize events close to each other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in this case the rest of the page will be smoothly resizing and the textarea will just jump to the correct size at the end right? Wouldn't it be better to have it also smoothly resize?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the delay is so small that people won't really notice it if they're flipping their phone. The only ones that would would be developers, but I'd prioritize less repaints to dev satisfaction while resizing the window.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the delay is small but if you get a resize event every 9ms for 1s, doesn't that mean the resize won't actually trigger until after 1s? (or I'm misunderstanding how debounceTime works)

"window of time required to wait for emission silence before emitting the most recent source value" (from http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-debounceTime)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but the way this usually plays out is that the browser either fires a few of them at a time if you change your screen orientation, or one per pixel if you're resizing it manually. It's really hard to move your browser resize handle at a constant 1px per 9ms since it's about the speed of human reaction time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auditTime seems like a more natural fit for this though, since it will give us the most recent value every 10ms (or we could up it to 16ms which is ~60fps)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I've switched it.

/**
* Resize the textarea to fit its content.
* @param force Whether to force a height recalculation. By default the height will be
* recalculated only if the value changed since the last call.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indent

@crisbeto crisbeto force-pushed the 8610/autosize-resize branch from 23d4f08 to 4328501 Compare November 27, 2017 17:38
@crisbeto
Copy link
Member Author

Addressed the feedback @mmalerba.

@crisbeto crisbeto force-pushed the 8610/autosize-resize branch from 4328501 to 1fe3e53 Compare November 27, 2017 18:55
@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 27, 2017
@mmalerba mmalerba added this to the 6.0 milestone Nov 27, 2017
@mmalerba
Copy link
Contributor

mmalerba commented Nov 27, 2017

I think this is technically breaking due to the addition of NgZone to the constructor, so added to 6.0 milestone.

If we want to get it in sooner we could make the NgZone optional and just skip adding the resize listener if none is passed

@crisbeto crisbeto force-pushed the 8610/autosize-resize branch from 1fe3e53 to 03c73b2 Compare November 27, 2017 19:18
@crisbeto
Copy link
Member Author

Made it optional, although I'm not sure how common it would be to extend this directive in particular.

@crisbeto crisbeto force-pushed the 8610/autosize-resize branch from 03c73b2 to aec5a66 Compare November 27, 2017 19:19
constructor(
private _elementRef: ElementRef,
private _platform: Platform,
private _ngZone?: NgZone) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add TODO to make non-optional at next major

@mmalerba mmalerba modified the milestones: 6.0, 5.1 Nov 27, 2017
Fixes the autosize textarea not recalculating its height when the viewport size has changed.

Fixes angular#8610.
@crisbeto crisbeto force-pushed the 8610/autosize-resize branch from aec5a66 to 1a11ffa Compare November 27, 2017 19:44
@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Dec 6, 2017
@mmalerba mmalerba merged commit b8664b8 into angular:master Dec 8, 2017
mmalerba pushed a commit that referenced this pull request Dec 8, 2017
Fixes the autosize textarea not recalculating its height when the viewport size has changed.

Fixes #8610.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

matTextareaAutosize does not get updated on window resize
3 participants