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] Support adornment full width #8835

Merged
merged 1 commit into from Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions docs/src/pages/demos/text-fields/InputAdornments.js
@@ -1,6 +1,7 @@
/* eslint-disable flowtype/require-valid-file-annotation */

import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import IconButton from 'material-ui/IconButton';
Expand All @@ -17,6 +18,9 @@ const styles = theme => ({
formControl: {
margin: theme.spacing.unit,
},
withoutLabel: {
marginTop: theme.spacing.unit * 3,
},
});

class InputAdornments extends React.Component {
Expand Down Expand Up @@ -44,7 +48,7 @@ class InputAdornments extends React.Component {

return (
<div className={classes.root}>
<FormControl className={classes.formControl}>
<FormControl fullWidth className={classes.formControl}>
<InputLabel htmlFor="amount">Amount</InputLabel>
<Input
id="amount"
Expand All @@ -53,15 +57,14 @@ class InputAdornments extends React.Component {
startAdornment={<InputAdornment position="start">$</InputAdornment>}
/>
</FormControl>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="weight">Weight</InputLabel>
<FormControl className={classNames(classes.formControl, classes.withoutLabel)}>
<Input
id="weight"
value={this.state.weight}
onChange={this.handleChange('weight')}
endAdornment={<InputAdornment position="end">Kg</InputAdornment>}
/>
<FormHelperText>Some important helper text</FormHelperText>
<FormHelperText>Weight</FormHelperText>
</FormControl>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="password">Password</InputLabel>
Expand Down
8 changes: 2 additions & 6 deletions src/Input/Input.js
Expand Up @@ -64,7 +64,8 @@ export const styles = (theme: Object) => {
return {
root: {
// Mimics the default input display property used by browsers for an input.
display: 'inline-block',
display: 'inline-flex',
Copy link

Choose a reason for hiding this comment

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

This change introduced a regression, see #8973

alignItems: 'baseline',
position: 'relative',
fontFamily: theme.typography.fontFamily,
color: theme.palette.input.inputText,
Expand Down Expand Up @@ -140,10 +141,6 @@ export const styles = (theme: Object) => {
'&:focus::-ms-input-placeholder': placeholderVisible, // Edge
},
},
inputAdorned: {
display: 'inline-block',
width: 'auto',
},
inputDense: {
paddingTop: theme.spacing.unit / 2,
},
Expand Down Expand Up @@ -526,7 +523,6 @@ class Input extends React.Component<ProvidedProps & Props, State> {
[classes.inputSearch]: type === 'search',
[classes.inputMultiline]: multiline,
[classes.inputDense]: margin === 'dense',
[classes.inputAdorned]: startAdornment || endAdornment,
},
inputPropsClassName,
);
Expand Down
14 changes: 2 additions & 12 deletions src/Input/Input.spec.js
Expand Up @@ -381,6 +381,7 @@ describe('<Input />', () => {
it(`is false for value ${value}`, () => {
assert.strictEqual(isDirty({ value }), false);
});

it(`is false for SSR defaultValue ${value}`, () => {
assert.strictEqual(isDirty({ defaultValue: value }, true), false);
});
Expand All @@ -403,24 +404,13 @@ describe('<Input />', () => {

assert.strictEqual(wrapper.childAt(0).type(), InputAdornment);
});

it('should render adornment after input', () => {
const wrapper = shallow(
<Input endAdornment={<InputAdornment position="end">$</InputAdornment>} />,
);

assert.strictEqual(wrapper.childAt(1).type(), InputAdornment);
});
it('child input should have adorned classes', () => {
const wrapper = shallow(
<Input endAdornment={<InputAdornment position="end">$</InputAdornment>} />,
);

assert.strictEqual(wrapper.childAt(0).hasClass(classes.inputAdorned), true);
});
it('child input should have unadorned classes', () => {
const wrapper = shallow(<Input />);

assert.strictEqual(wrapper.childAt(0).hasClass(classes.inputAdorned), false);
});
});
});
1 change: 0 additions & 1 deletion src/Input/InputAdornment.js
Expand Up @@ -8,7 +8,6 @@ import withStyles from '../styles/withStyles';

export const styles = (theme: Object) => ({
root: {
display: 'inline-block',
'label + div > &': {
marginTop: -theme.spacing.unit * 2,
},
Expand Down
1 change: 1 addition & 0 deletions src/Select/Select.js
Expand Up @@ -12,6 +12,7 @@ import { isMuiElement } from '../utils/reactHelpers';
export const styles = (theme: Object) => ({
root: {
position: 'relative',
width: '100%',
},
select: {
'-moz-appearance': 'none', // Remove Firefox custom style
Expand Down