Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextField] Make it meet guidelines #6566

Merged
merged 45 commits into from May 30, 2017
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7f966d0
Adjusted styles accordingto specs, fixed #6425
kybarg Apr 10, 2017
10a5c0f
Merge branch 'callemall/next' into next-text-field-guidelines
kybarg Apr 11, 2017
6e8ad06
Fixes, simplified styles
kybarg Apr 11, 2017
b5fb82a
Removed dead `TextFieldLabel` component as for #6580
kybarg Apr 11, 2017
6cece85
Added colors according to specs, `InputLabel` disabled prop
kybarg Apr 12, 2017
7b7fa13
Avoiding label flicker and blurry text in webkit browsers
kybarg Apr 12, 2017
4716659
More smooth label animation.
kybarg Apr 12, 2017
6f83e5b
More smooth font-size animation
kybarg Apr 12, 2017
186a251
Proper error color, added `FormHelperText` component
kybarg Apr 12, 2017
7abcec9
FormHelperText docs
kybarg Apr 12, 2017
d02154c
Fixed lint errors
kybarg Apr 12, 2017
dffc976
Added new component to styles order, fixes
kybarg Apr 15, 2017
890217f
Merge remote-tracking branch 'refs/remotes/callemall/next' into next-…
kybarg Apr 15, 2017
0b15230
Fixed disabled border style
kybarg Apr 15, 2017
f27ea99
Solve conflicts
kybarg May 26, 2017
b11a2e8
FormHelperText exports
kybarg May 26, 2017
7a3d1f4
Merge remote-tracking branch 'refs/remotes/callemall/next' into next-…
kybarg May 26, 2017
710e605
Remove unused TextFieldLabel
kybarg May 26, 2017
ff1abe5
Merge remote-tracking branch 'callemall/next' into next-text-field-gu…
kybarg May 27, 2017
0061db1
Form helper fixes, test, docs
kybarg May 27, 2017
6af7c88
Merge remote-tracking branch 'refs/remotes/callemall/next' into next-…
kybarg May 27, 2017
0565e94
TextField tests for FormHelperText
kybarg May 27, 2017
c3bde34
Get rid of TextFieldLabel.md, added tests for InputLabel
kybarg May 27, 2017
c740da2
Added tests for FormControl
kybarg May 27, 2017
760eb25
Merge remote-tracking branch 'refs/remotes/callemall/next' into next-…
kybarg May 29, 2017
4e16f7c
Make dirty if `defaultValue` is set
kybarg May 29, 2017
e7e7f47
Fix helper text font
kybarg May 29, 2017
38d4043
Fix label "flicker" in webkit browsers.
kybarg May 29, 2017
2f70c6c
Use `theme.spacing.unit` instead of number values
kybarg May 29, 2017
1457b96
Disabled composed text field demo
kybarg May 29, 2017
5fe667a
Fixed type check
kybarg May 29, 2017
5d6970d
Fixed type check error
kybarg May 29, 2017
612b02c
Make `ComposedTextFiled` accept disabled prop
kybarg May 29, 2017
ae3d010
Fixed lint
kybarg May 29, 2017
3cd4b99
Fixed docs and input
kybarg May 29, 2017
9b40eee
Exposed FormHelperTextProps and InputLabelProps
kybarg May 29, 2017
428d870
Fixed docs
kybarg May 29, 2017
489de60
Merge remote-tracking branch 'refs/remotes/callemall/next' into next-…
kybarg May 29, 2017
a8a9a6c
Fixed multiline styles
kybarg May 29, 2017
3043877
Placeholder + Label behaviour
kybarg May 29, 2017
f30dbea
Fixes
kybarg May 29, 2017
0419922
Fixed lint errors
kybarg May 29, 2017
c37fe6e
Merge remote-tracking branch 'refs/remotes/callemall/next' into next-…
kybarg May 30, 2017
30be343
Typo fixes
kybarg May 30, 2017
60ae4d7
Typo fixes 2
kybarg May 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/pages/component-api/Form/FormControl.md
Expand Up @@ -7,6 +7,7 @@ Provides context such as dirty/focused/error/required for form inputs.
|:-----|:-----|:--------|:------------|
| children | node | | The contents of the form control. |
| classes | object | | Useful to extend the style applied to components. |
| disabled | bool | false | If `true`, the label should be displayed in an disabled state. |
| error | bool | false | If `true`, the label should be displayed in an error state. |
| required | bool | false | If `true`, the label will indicate that the input is required. |

Expand Down
@@ -1,4 +1,4 @@
# TextFieldLabel
# FormHelperText



Expand All @@ -7,24 +7,22 @@
|:-----|:-----|:--------|:------------|
| children | node | | The content of the component. |
| classes | object | | Useful to extend the style applied to components. |
| disableAnimation | bool | false | If `true`, the transition animation is disabled. |
| error | bool | | If `true`, the label is displayed in an error state. |
| focused | bool | | If `true`, the input of this label is focused. |
| required | bool | | If `true`, the label will indicate that the input is required. |
| shrink | bool | false | If `true`, the label is shrunk. |
| className | string | | The CSS class name of the root element. |
| disabled | bool | | Whether the helper text should be displayed in an disabled state. |
| error | bool | | Whether the helper text should be displayed in an error state. |

Any other properties supplied will be spread to the root element.
## Classes

You can overrides all the class names injected by Material-UI thanks to the `classes` property.
This property accepts the following keys:
- `root`
- `shrink`
- `animated`
- `error`
- `disabled`

Have a look at [overriding with class names](/customization/overrides#overriding-with-class-names)
section for more detail.

If using the `overrides` key of the theme as documented
[here](/customization/themes#customizing-all-instances-of-a-component-type),
you need to use the following style sheet name: `MuiTextFieldLabel`.
you need to use the following style sheet name: `MuiFormHelperText`.
2 changes: 2 additions & 0 deletions docs/src/pages/component-api/Form/FormLabel.md
Expand Up @@ -7,6 +7,7 @@
|:-----|:-----|:--------|:------------|
| children | node | | The content of the component. |
| classes | object | | Useful to extend the style applied to components. |
| disabled | bool | | Whether the label should be displayed in an disabled state. |
| error | bool | | Whether the label should be displayed in an error state. |
| focused | bool | | If `true`, the input of this label is focused (used by `FormGroup` components). |
| required | bool | | If `true`, the label will indicate that the input is required. |
Expand All @@ -19,6 +20,7 @@ This property accepts the following keys:
- `root`
- `focused`
- `error`
- `disabled`

Have a look at [overriding with class names](/customization/overrides#overriding-with-class-names)
section for more detail.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/component-api/Input/Input.md
Expand Up @@ -9,7 +9,7 @@
| className | string | | The CSS class name of the wrapper element. |
| component | union:&nbsp;string<br>&nbsp;func<br> | | The component used for the root node. Either a string to use a DOM element or a component. It's an `input` by default. |
| defaultValue | string | | The default value of the `Input` element. |
| disabled | bool | false | If `true`, the input will be disabled. |
| disabled | bool | | If `true`, the input will be disabled. |
| disableUnderline | bool | false | If `true`, the input will not have an underline. |
| error | bool | | If `true`, the input will indicate an error. |
| id | string | | |
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/component-api/Input/InputLabel.md
Expand Up @@ -8,6 +8,7 @@
| children | node | | The contents of the `InputLabel`. |
| classes | object | | Useful to extend the style applied to components. |
| disableAnimation | bool | false | If `true`, the transition animation is disabled. |
| disabled | bool | false | If `true`, apply disabled class. |
| error | bool | | If `true`, the label will be displayed in an error state. |
| focused | bool | | If `true`, the input of this label is focused. |
| required | bool | | if `true`, the label will indicate that the input is required. |
Expand All @@ -22,6 +23,7 @@ This property accepts the following keys:
- `formControl`
- `shrink`
- `animated`
- `disabled`

Have a look at [overriding with class names](/customization/overrides#overriding-with-class-names)
section for more detail.
Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/component-api/Progress/CircularProgress.md
Expand Up @@ -6,10 +6,10 @@
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| classes | object | | Useful to extend the style applied to components. |
| size | number | 40 | The size of the circle. |
| mode | enum:<br>&nbsp;'determinate'<br>&nbsp;'indeterminate' | 'indeterminate' | The mode of show your progress. Indeterminate for when there is no value for progress. Determinate for controlled progress value. |
| max | number | 100 | The max value of progress in determinate mode. |
| min | number | 0 | TThe min value of progress in determinate mode. |
| min | number | 0 | The min value of progress in determinate mode. |
| mode | enum:&nbsp;'determinate'<br>&nbsp;'indeterminate'<br> | 'indeterminate' | The mode of show your progress. Indeterminate for when there is no value for progress. Determinate for controlled progress value. |
| size | number | 40 | The size of the circle. |
| value | number | 0 | The value of progress in determinate mode. |

Any other properties supplied will be spread to the root element.
Expand Down
4 changes: 4 additions & 0 deletions docs/src/pages/component-api/TextField/TextField.md
Expand Up @@ -8,9 +8,13 @@
| defaultValue | string | | The default value of the `Input` element. |
| disabled | bool | | If `true`, the input will be disabled. |
| error | bool | | If `true`, the label will be displayed in an error state. |
| helperText | node | | The helper text content. |
| helperTextClassName | string | | The CSS class name of the helper text element. |
| FormHelperTextProps | object | | Properties applied to the `FormHelperText` element. |
| id | string | | |
| inputClassName | string | | The CSS class name of the `input` element. |
| InputClassName | string | | The CSS class name of the `Input` element. |
| InputLabelProps | object | | Properties applied to the `InputLabel` element. |
| inputProps | object | | Properties applied to the `input` element. |
| InputProps | object | | Properties applied to the `Input` element. |
| inputRef | function | | Use that property to pass a ref callback to the native input component. |
Expand Down
22 changes: 22 additions & 0 deletions docs/src/pages/component-demos/text-fields/ComposedTextField.js
Expand Up @@ -6,6 +6,7 @@ import { withStyles, createStyleSheet } from 'material-ui/styles';
import Input from 'material-ui/Input';
import InputLabel from 'material-ui/Input/InputLabel';
import FormControl from 'material-ui/Form/FormControl';
import FormHelperText from 'material-ui/Form/FormHelperText';

const styleSheet = createStyleSheet('ComposedTextField', theme => ({
container: {
Expand Down Expand Up @@ -37,6 +38,27 @@ class ComposedTextField extends Component {
</InputLabel>
<Input id="name" value={this.state.name} onChange={this.handleChange} />
</FormControl>
<FormControl className={classes.input}>
<InputLabel htmlFor="name">
Name
</InputLabel>
<Input id="name" value={this.state.name} onChange={this.handleChange} />
<FormHelperText>Some important helper text</FormHelperText>
</FormControl>
<FormControl className={classes.input} disabled>
<InputLabel htmlFor="name">
Name
</InputLabel>
<Input id="name" value={this.state.name} onChange={this.handleChange} />
<FormHelperText>Some important helper text</FormHelperText>
</FormControl>
<FormControl className={classes.input} error>
<InputLabel htmlFor="name">
Name
</InputLabel>
<Input id="name" value={this.state.name} onChange={this.handleChange} />
<FormHelperText>Some important helper text</FormHelperText>
</FormControl>
</div>
);
}
Expand Down
16 changes: 16 additions & 0 deletions docs/src/pages/component-demos/text-fields/TextFields.js
Expand Up @@ -77,6 +77,22 @@ class TextFields extends Component {
defaultValue="2017-05-24"
className={classes.input}
/>
<TextField
id="helperText"
label="Helper text"
type="text"
defaultValue="Default Value"
className={classes.input}
helperText="Some important text"
/>
<TextField
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Firefox do not like that example:
capture d ecran 2017-05-29 a 21 41 06

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviertassinari I guess jss doens't prefix placeholder selector. My bad 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which Firefox version is it?

id="placeholder"
label="Label"
className={classes.input}
type="text"
InputProps={{ placeholder: 'Placeholder' }}
helperText="Helper text"
/>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/component-demos/text-fields/text-fields.md
@@ -1,5 +1,5 @@
---
components: Input, TextField, TextFieldLabel
components: Input, TextField, FormHelperText
---

# Text Fields
Expand Down
20 changes: 18 additions & 2 deletions src/Form/FormControl.js
@@ -1,10 +1,11 @@
// @flow weak

import React, { Component } from 'react';
import React, { Children, Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { createStyleSheet } from 'jss-theme-reactor';
import withStyles from '../styles/withStyles';
import { isDirty } from '../Input/Input';

export const styleSheet = createStyleSheet('MuiFormControl', {
root: {
Expand All @@ -22,6 +23,7 @@ export const styleSheet = createStyleSheet('MuiFormControl', {
*/
class FormControl extends Component {
static defaultProps = {
disabled: false,
error: false,
required: false,
};
Expand All @@ -32,12 +34,13 @@ class FormControl extends Component {
};

getChildContext() {
const { error, required } = this.props;
const { disabled, error, required } = this.props;
const { dirty, focused } = this.state;

return {
muiFormControl: {
dirty,
disabled,
error,
focused,
required,
Expand All @@ -49,6 +52,14 @@ class FormControl extends Component {
};
}

componentWillMount() {
Children.forEach(this.props.children, child => {
if (child && child.type && child.type.muiName === 'Input' && isDirty(child.props)) {
this.setState({ dirty: true });
}
});
}

handleFocus = () => {
if (this.props.onFocus) {
this.props.onFocus();
Expand Down Expand Up @@ -84,6 +95,7 @@ class FormControl extends Component {
children,
classes,
className,
disabled, // eslint-disable-line no-unused-vars
error, // eslint-disable-line no-unused-vars
...other
} = this.props;
Expand Down Expand Up @@ -114,6 +126,10 @@ FormControl.propTypes = {
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the label should be displayed in an disabled state.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'a disabled state'

disabled: PropTypes.bool,
/**
* If `true`, the label should be displayed in an error state.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Form/FormControl.spec.js
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import { spy } from 'sinon';
import { assert } from 'chai';
import { createShallow } from '../test-utils';
import Input from '../Input';
import FormControl, { styleSheet } from './FormControl';

describe('<FormControl />', () => {
Expand Down Expand Up @@ -47,6 +48,18 @@ describe('<FormControl />', () => {
});
});

describe('should be dirty if has input with value set', () => {
let wrapper;

beforeEach(() => {
wrapper = shallow(<FormControl><Input value="bar" /></FormControl>);
});

it('should be dirty initially', () => {
assert.strictEqual(wrapper.state().dirty, true);
});
});

describe('muiFormControl child context', () => {
let wrapper;
let muiFormControlContext;
Expand Down
90 changes: 90 additions & 0 deletions src/Form/FormHelperText.js
@@ -0,0 +1,90 @@
// @flow weak

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { createStyleSheet } from 'jss-theme-reactor';
import withStyles from '../styles/withStyles';

export const styleSheet = createStyleSheet('MuiFormHelperText', theme => ({
root: {
color: theme.palette.input.helperText,
fontFamily: theme.typography.fontFamily,
fontSize: 12,
lineHeight: 1.4,
margin: 0,
},
error: {
color: theme.palette.error.A400,
},
disabled: {
color: theme.palette.input.disabled,
},
}));

function FormHelperText(props, context) {
const {
children,
classes,
className: classNameProp,
disabled: disabledProp,
error: errorProp,
...other
} = props;
const { muiFormControl } = context;

let disabled = disabledProp;
let error = errorProp;

if (muiFormControl && typeof disabled === 'undefined') {
disabled = muiFormControl.disabled;
}

if (muiFormControl && typeof error === 'undefined') {
error = muiFormControl.error;
}

const className = classNames(
classes.root,
{
[classes.disabled]: disabled,
[classes.error]: error,
},
classNameProp,
);

return (
<p className={className} {...other}>
{children}
</p>
);
}

FormHelperText.propTypes = {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Whether the helper text should be displayed in an disabled state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'If true,' ... 'a disabled state.'

*/
disabled: PropTypes.bool,
/**
* Whether the helper text should be displayed in an error state.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'If true,'

error: PropTypes.bool,
};

FormHelperText.contextTypes = {
muiFormControl: PropTypes.object,
};

export default withStyles(styleSheet)(FormHelperText);