Skip to content

Make sure that when we have a value, we also show the label #14

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions FloatingLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@ const Textbox = t.form.Textbox
class FloatingLabel extends Textbox {
constructor (props) {
super(props);

// run the value through the transformer, because 0 is also a valid input in some cases
const hasValue = this.getTransformer().format(props.value)

this.state = {
fieldFocused: (props.value) ? true : false,
value: (props.value) ? String(props.value) : undefined,
fadeAnim: (props.value) ? new Animated.Value(1) : new Animated.Value(0),
fieldFocused: hasValue ? true : false,
value: hasValue ? String(props.value) : undefined,
fadeAnim: hasValue ? new Animated.Value(1) : new Animated.Value(0),
placeholderString: undefined,
};
}

componentWillReceiveProps(next) {

// Make sure that when we have a value, we also show the label
if(this.props.value !== next.value && this.getTransformer().format(next.value)) {
this.setState({
fadeAnim: new Animated.Value(1),
})
}

super.componentWillReceiveProps(next)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this line needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. The parent component sets the internal state for value. We could either use this, or set the state ourself. But I thought it would be better to let the parent class manage what it is supposed to manage anyway.

}


getTemplate () {
let self = this
return function (locals) {
Expand Down