-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.js
78 lines (68 loc) · 2.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import _ from 'underscore';
import styles from '../../styles/styles';
import * as styleConst from './styleConst';
import BaseTextInput from './BaseTextInput';
import * as baseTextInputPropTypes from './baseTextInputPropTypes';
import DomUtils from '../../libs/DomUtils';
import Visibility from '../../libs/Visibility';
class TextInput extends React.Component {
componentDidMount() {
if (this.props.disableKeyboard) {
this.textInput.setAttribute('inputmode', 'none');
}
if (this.props.name) {
this.textInput.setAttribute('name', this.props.name);
}
// Forcefully activate the soft keyboard when the user switches between tabs while input was focused.
this.removeVisibilityListener = Visibility.onVisibilityChange(() => {
if (!Visibility.isVisible() || !this.textInput || DomUtils.getActiveElement() !== this.textInput) {
return;
}
this.textInput.blur();
this.textInput.focus();
});
}
componentWillUnmount() {
if (!this.removeVisibilityListener) {
return;
}
this.removeVisibilityListener();
}
render() {
const isLabeledMultiline = Boolean(this.props.label.length) && this.props.multiline;
const labelAnimationStyle = {
'--active-label-translate-y': `${styleConst.ACTIVE_LABEL_TRANSLATE_Y}px`,
'--active-label-scale': `${styleConst.ACTIVE_LABEL_SCALE}`,
'--label-transition-duration': `${styleConst.LABEL_ANIMATION_DURATION}ms`,
};
return (
<BaseTextInput
// eslint-disable-next-line react/jsx-props-no-spreading
{...this.props}
innerRef={(el) => {
this.textInput = el;
if (!this.props.innerRef) {
return;
}
if (_.isFunction(this.props.innerRef)) {
this.props.innerRef(el);
return;
}
this.props.innerRef.current = el;
}}
inputStyle={[styles.baseTextInput, styles.textInputDesktop, isLabeledMultiline ? styles.textInputMultiline : {}, ...this.props.inputStyle]}
textInputContainerStyles={[labelAnimationStyle, ...this.props.textInputContainerStyles]}
/>
);
}
}
TextInput.propTypes = baseTextInputPropTypes.propTypes;
TextInput.defaultProps = baseTextInputPropTypes.defaultProps;
export default React.forwardRef((props, ref) => (
<TextInput
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
innerRef={ref}
/>
));