diff --git a/src/TextField/TextField.jsx b/src/TextField/TextField.jsx
index b524a29fbc5703..b503bd54377d0f 100644
--- a/src/TextField/TextField.jsx
+++ b/src/TextField/TextField.jsx
@@ -9,6 +9,7 @@ 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 TextFieldLabel from './TextFieldLabel';
import TextFieldUnderline from './TextFieldUnderline';
import warning from 'warning';
@@ -118,6 +119,7 @@ const TextField = React.createClass({
let props = (this.props.children) ? this.props.children.props : this.props;
return {
+ isFocused: false,
errorText: this.props.errorText,
hasValue: isValid(props.value) || isValid(props.defaultValue) ||
(props.valueLink && isValid(props.valueLink.value)),
@@ -188,16 +190,7 @@ const TextField = React.createClass({
transition: Transitions.easeOut(),
},
floatingLabel: {
- position: 'absolute',
- lineHeight: '22px',
- top: 38,
- opacity: 1,
color: hintColor,
- transition: Transitions.easeOut(),
- 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)',
@@ -222,15 +215,12 @@ const TextField = React.createClass({
font: 'inherit',
});
-
if (this.state.isFocused) {
styles.floatingLabel.color = focusColor;
- styles.floatingLabel.transform = 'perspective(1px) scale(0.75) translate3d(2px, -28px, 0)';
}
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)';
}
if (props.floatingLabelText) {
@@ -289,12 +279,15 @@ const TextField = React.createClass({
) : null;
let floatingLabelTextElement = floatingLabelText ? (
-
+
) : null;
let inputProps;
diff --git a/src/TextField/TextFieldLabel.jsx b/src/TextField/TextFieldLabel.jsx
new file mode 100644
index 00000000000000..18d91f400b2a92
--- /dev/null
+++ b/src/TextField/TextFieldLabel.jsx
@@ -0,0 +1,97 @@
+import React from 'react';
+import Transitions from '../styles/transitions';
+import styleUtils from '../utils/styles';
+
+const propTypes = {
+ /**
+ * The material-ui theme applied to this component.
+ */
+ muiTheme: React.PropTypes.object.isRequired,
+
+ /**
+ * The css class name of the root element.
+ */
+ className: React.PropTypes.string,
+
+ /**
+ * The label contents.
+ */
+ children: React.PropTypes.node,
+
+ /**
+ * Disables the label if set to true.
+ */
+ disabled: React.PropTypes.bool,
+
+ /**
+ * True if the floating label should shrink.
+ */
+ shrink: React.PropTypes.bool,
+
+ /**
+ * The id of the target element that this label should refer to.
+ */
+ htmlFor: React.PropTypes.string,
+
+ /**
+ * Callback function for when the label is selected via a touch tap.
+ */
+ onTouchTap: React.PropTypes.func,
+
+ /**
+ * Override the inline-styles of the floating label.
+ */
+ style: React.PropTypes.object,
+};
+
+const defaultProps = {
+ disabled: false,
+ shrink: false,
+};
+
+const TextFieldLabel = (props) => {
+
+ const {
+ muiTheme,
+ className,
+ children,
+ disabled,
+ shrink,
+ htmlFor,
+ style,
+ onTouchTap,
+ } = props;
+
+ const styles = {
+ root: {
+ position: 'absolute',
+ lineHeight: '22px',
+ top: 38,
+ transition: Transitions.easeOut(),
+ zIndex: 1, // Needed to display label above Chrome's autocomplete field background
+ cursor: disabled ? 'default' : 'text',
+ transform: shrink
+ ? 'perspective(1px) scale(0.75) translate3d(2px, -28px, 0)'
+ : 'scale(1) translate3d(0, 0, 0)',
+ transformOrigin: 'left top',
+ pointerEvents: shrink ? 'none' : 'auto',
+ userSelect: 'none',
+ },
+ };
+
+ return (
+
+ );
+};
+
+TextFieldLabel.propTypes = propTypes;
+TextFieldLabel.defaultProps = defaultProps;
+
+export default TextFieldLabel;