Javi Velasco 2016-11-05 12:22:44 +01:00
parent 00a0a9f16a
commit e240cf237e
1 changed files with 10 additions and 3 deletions

View File

@ -59,22 +59,27 @@ const factory = (Input) => {
componentWillUpdate (nextProps, nextState) {
if (!this.state.active && nextState.active) {
events.addEventsToDocument({click: this.handleDocumentClick});
events.addEventsToDocument(this.getDocumentEvents());
}
}
componentDidUpdate (prevProps, prevState) {
if (prevState.active && !this.state.active) {
events.removeEventsFromDocument({click: this.handleDocumentClick});
events.removeEventsFromDocument(this.getDocumentEvents());
}
}
componentWillUnmount () {
if (this.state.active) {
events.removeEventsFromDocument({click: this.handleDocumentClick});
events.removeEventsFromDocument(this.getDocumentEvents());
}
}
getDocumentEvents = () => ({
click: this.handleDocumentClick,
touchend: this.handleDocumentClick
});
close = () => {
if (this.state.active) {
this.setState({active: false});
@ -94,6 +99,7 @@ const factory = (Input) => {
const up = this.props.auto ? client.top > ((screen_height / 2) + client.height) : false;
if (this.props.onClick) this.props.onClick(event);
if (this.props.onFocus) this.props.onFocus(event);
if (this.inputNode) this.inputNode.blur();
this.setState({active: true, up});
};
@ -169,6 +175,7 @@ const factory = (Input) => {
onClick={this.handleClick}
required={this.props.required}
readOnly
ref={node => { this.inputNode = node && node.getWrappedInstance(); }}
type={template && selected ? 'hidden' : null}
value={selected && selected.label ? selected.label : ''}
/>