From f82b3ac2bd83206d1b4778c579df974610a25ac9 Mon Sep 17 00:00:00 2001 From: Evan Henley Date: Sun, 24 Apr 2016 17:42:01 -0500 Subject: [PATCH] [TextField] add floatingLabelFocusStyles prop --- .../components/TextField/ExampleCustomize.js | 13 +++- src/TextField/TextField.js | 14 ++-- src/TextField/TextFieldLabel.js | 69 +++++++++++-------- src/TextField/TextFieldLabel.spec.js | 25 +++++++ 4 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 src/TextField/TextFieldLabel.spec.js diff --git a/docs/src/app/components/pages/components/TextField/ExampleCustomize.js b/docs/src/app/components/pages/components/TextField/ExampleCustomize.js index 593ca70d219c24..4e024b3998c6f2 100644 --- a/docs/src/app/components/pages/components/TextField/ExampleCustomize.js +++ b/docs/src/app/components/pages/components/TextField/ExampleCustomize.js @@ -1,6 +1,6 @@ import React from 'react'; import TextField from 'material-ui/TextField'; -import {orange500} from 'material-ui/styles/colors'; +import {orange500, blue500} from 'material-ui/styles/colors'; const styles = { errorStyle: { @@ -9,6 +9,12 @@ const styles = { underlineStyle: { borderColor: orange500, }, + floatingLabelStyle: { + color: orange500, + }, + floatingLabelFocusStyle: { + color: blue500, + }, }; const TextFieldExampleCustomize = () => ( @@ -29,6 +35,11 @@ const TextFieldExampleCustomize = () => (
+ ); diff --git a/src/TextField/TextField.js b/src/TextField/TextField.js index 7fdaf45bb47acf..8dfcb1980886ce 100644 --- a/src/TextField/TextField.js +++ b/src/TextField/TextField.js @@ -47,7 +47,6 @@ const getStyles = (props, context, state) => { }, floatingLabel: { color: hintColor, - pointerEvents: 'none', }, input: { WebkitTapHighlightColor: 'rgba(0,0,0,0)', // Remove mobile color flashing (deprecated) @@ -73,14 +72,14 @@ const getStyles = (props, context, state) => { font: 'inherit', }); - if (state.isFocused) { - styles.floatingLabel.color = focusColor; - } - if (state.hasValue) { styles.floatingLabel.color = fade(props.disabled ? disabledTextColor : floatingLabelColor, 0.5); } + if (state.isFocused) { + styles.floatingLabel.color = focusColor; + } + if (props.floatingLabelText) { styles.input.boxSizing = 'border-box'; @@ -139,6 +138,10 @@ class TextField extends Component { * If true, the floating label will float even when there is no value. */ floatingLabelFixed: PropTypes.bool, + /** + * The style object to use to override floating label styles when focused. + */ + floatingLabelFocusStyle: PropTypes.object, /** * The style object to use to override floating label styles. */ @@ -419,6 +422,7 @@ class TextField extends Component { { 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(0, -28px, 0)' : - 'scale(1) translate3d(0, 0, 0)', - transformOrigin: 'left top', - pointerEvents: shrink ? 'none' : 'auto', - userSelect: 'none', - }, - }; - const {prepareStyles} = muiTheme; + const styles = getStyles(props); return (