From 873bd303e804e99c20c233bbb6f6ffdef8f156ff Mon Sep 17 00:00:00 2001 From: Neil Gabbadon Date: Thu, 17 Dec 2015 01:15:20 -0500 Subject: [PATCH 1/2] Separate TextFieldHint into separate internal component. --- src/TextField/TextField.jsx | 47 +++++++++-------------- src/TextField/TextFieldHint.jsx | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 src/TextField/TextFieldHint.jsx diff --git a/src/TextField/TextField.jsx b/src/TextField/TextField.jsx index b3fd7b16d8ae8a..fca7150bc0ed21 100644 --- a/src/TextField/TextField.jsx +++ b/src/TextField/TextField.jsx @@ -8,6 +8,7 @@ import EnhancedTextarea from '../enhanced-textarea'; import DefaultRawTheme from '../styles/raw-themes/light-raw-theme'; import ThemeManager from '../styles/theme-manager'; import ContextPure from '../mixins/context-pure'; +import TextFieldHint from './TextFieldHint'; import TextFieldUnderline from './TextFieldUnderline'; import warning from 'warning'; @@ -178,13 +179,17 @@ const TextField = React.createClass({ color: errorColor, transition: Transitions.easeOut(), }, - hint: { + floatingLabel: { position: 'absolute', lineHeight: '22px', + top: 38, opacity: 1, color: hintColor, transition: Transitions.easeOut(), - bottom: 12, + zIndex: 1, // Needed to display label above Chrome's autocomplete field background + cursor: 'text', + transform: 'scale(1) translate3d(0, 0, 0)', + transformOrigin: 'left top', }, input: { tapHighlightColor: 'rgba(0,0,0,0)', @@ -202,17 +207,6 @@ const TextField = React.createClass({ styles.error = this.mergeStyles(styles.error, props.errorStyle); - styles.floatingLabel = this.mergeStyles(styles.hint, { - lineHeight: '22px', - top: 38, - bottom: 'none', - opacity: 1, - zIndex: 1, // Needed to display label above Chrome's autocomplete field background - cursor: 'text', - transform: 'scale(1) translate3d(0, 0, 0)', - transformOrigin: 'left top', - }); - styles.textarea = this.mergeStyles(styles.input, { marginTop: props.floatingLabelText ? 36 : 12, marginBottom: props.floatingLabelText ? -36 : -12, @@ -229,17 +223,11 @@ const TextField = React.createClass({ if (this.state.hasValue) { styles.floatingLabel.color = ColorManipulator.fade(props.disabled ? disabledTextColor : floatingLabelColor, 0.5); styles.floatingLabel.transform = 'perspective(1px) scale(0.75) translate3d(2px, -28px, 0)'; - styles.hint.opacity = 0; } if (props.floatingLabelText) { - styles.hint.opacity = 0; styles.input.boxSizing = 'border-box'; - if (this.state.isFocused && !this.state.hasValue) { - styles.hint.opacity = 1; - } - if (!props.multiLine) { styles.input.marginTop = 14; } @@ -249,10 +237,6 @@ const TextField = React.createClass({ } } - if (props.style && props.style.height) { - styles.hint.lineHeight = props.style.height; - } - if (this.state.errorText) { if (this.state.isFocused) { styles.floatingLabel.color = styles.error.color; @@ -277,6 +261,7 @@ const TextField = React.createClass({ onBlur, onChange, onFocus, + style, type, underlineDisabledStyle, underlineFocusStyle, @@ -295,10 +280,6 @@ const TextField = React.createClass({
{this.state.errorText}
) : null; - let hintTextElement = hintText ? ( -
{hintText}
- ) : null; - let floatingLabelTextElement = floatingLabelText ? (