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

[TextField] Shrink form label when input is autofilled #3372

Closed
wants to merge 1 commit into from
Closed

[TextField] Shrink form label when input is autofilled #3372

wants to merge 1 commit into from

Conversation

antoinerousseau
Copy link
Contributor

Fixes #718.

@antoinerousseau antoinerousseau changed the title #718: shrink form label when input is autofilled Shrink form label when input is autofilled Feb 18, 2016
@simensen
Copy link

@antoinerousseau very cool! excited to see how this goes. is this failing test something related to your code or some other type of test failure?

@@ -289,6 +289,7 @@ const TextField = React.createClass({

return {
isFocused: false,
isAutofilled: false,
Copy link
Member

Choose a reason for hiding this comment

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

Could we use the hasValue state instead of this new isAutofilled even if we can't read the value for security converns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i don't see why not :)

@oliviertassinari oliviertassinari changed the title Shrink form label when input is autofilled [TextField] Shrink form label when input is autofilled Feb 18, 2016
@oliviertassinari
Copy link
Member

That looks good to me 👍.

@@ -351,7 +351,17 @@ const TextField = React.createClass({
},

_handleInputChange(e) {
this.setState({hasValue: isValid(e.target.value)});
let isAutofilled;
Copy link
Member

Choose a reason for hiding this comment

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

Actually, what do you think about running this test only if isValid(e.target.value) is false?
We could save some CPU cycles :). I don't know how expensive a try / catch and matches is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right!

@oliviertassinari oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Feb 19, 2016
@antoinerousseau
Copy link
Contributor Author

wait, i'm having a weird bug where chrome takes a millisecond or two between dispatching the change event and adding the :-webkit-autofill pseudo class, when autofilling...

@antoinerousseau
Copy link
Contributor Author

I could not come up with a better solution than checking the pseudo class after the component is mounted, since Chrome 48 does not dispatch a change event when autofilling...

But anyway, now it works well if you don't mind the timer ^^'

@mbrookes mbrookes added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Feb 29, 2016
@mbrookes
Copy link
Member

mbrookes commented Mar 2, 2016

@newoga - tagging you because I know you have an aversion to timers. 😄

Not sure there's an alternative though.

@newoga newoga added on hold There is a blocker, we need to wait PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Mar 3, 2016
@newoga
Copy link
Contributor

newoga commented Mar 3, 2016

I want to put this on hold for now. I'm not completely thrilled with this implementation (though not just because of the timer, so not @antoinerousseau's fault). The reality is we want TextField to become a controlled component, but there's not really an easy and natural way to use the input value that was set from autofill events.

This topic is being discussed in both the React and Angular communities (such as facebook/react#1159). Furthermore, based on the little I read, there may be edge cases that involve browsers outside of Chrome. I'm hesitant to put this logic in the TextField's componentDidMount component if it can be handled elsewhere or solved using other approaches.

If we wanted to go down this path, I'd probably argue for creating a separate Input component that handled these edgecases and using that in TextField instead of the standard input. It wouldn't be perfect, but we could at least have the Input component trigger an onChange event after it mounts if it was autofilled, that way TextField could keep it's current behavior. The implementation in Input would probably be a lot simpler and wouldn't require state or timers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work on hold There is a blocker, we need to wait PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants