Material-ui: Using a fullWidth TextField and InputAdornment messes with the input width

Created on 24 Oct 2017  路  8Comments  路  Source: mui-org/material-ui


When I use a TextField with an Adornment through the InputProps, if I set the width of the TextField component, either with fullWidth or with style property, the input field remains at the default width, only the root element takes the full space.

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

The input should receive the properties from the TextField even if I use the InputAdornment or not. Without it, the component renders ok.

Current Behavior


The root element changes its width, the input not.

Steps to Reproduce (for bugs)

Minimum example:
https://codesandbox.io/s/k2wn0166y7

Your Environment

| Tech | Version |
|--------------|---------|
| Material-UI | 1.0.0-beta.18 |
| React | 16.0.0 |
| browser | Google Chrome 61 |
| etc | |

bug 馃悰 TextField

Most helpful comment

If anyone's still struggling with this, this'll fix it for you.

```
amountField: {
boxSizing: 'border-box',
},

....

fullWidth
InputProps={{
className:classes.amountField,
startAdornment: $,
}}
/>

All 8 comments

+1 for this.

@oliviertassinari would it be possible to support <CircularProgress /> too as adornment on inputs?
Very nice to have on selects which load options asynchronously :)

@damianobarbati Have you tried doing so? How does it render? Do you see override generic enough we can move into the core components?

Yes, with the following (excerpt):

render = () => {
    ....
    const endAdornment = <CircularProgress />;

    const input = (
        <Input
            type={'text'}
            name={name}
            onFocus={onFocus}
            onBlur={onBlur}
            maxLength={maxLength}
            disabled={disabled}
            readOnly={readOnly}
            placeholder={placeholder}
            startAdornment={startAdornment}
            endAdornment={endAdornment}
            fullWidth={true}
            margin={'dense'}
        />
    );

    const selectValue = !multiple ?
        String(value || '') :
        (value || []) ;

    return (
        <FormControl className={cx(className)} fullWidth={true} required={!!required} error={!!errors}>
            {!disableLabel &&
            <InputLabel htmlFor={name}>{displayName || name}</InputLabel>
            }
            <MuiSelect input={input} value={selectValue} multiple={multiple} onChange={onChange} classes={{ icon: cx({ [classes.hideMoreIcon]: computing }) }}>{options}</MuiSelect>
            { !errors && description &&
            <FormHelperText>{description}</FormHelperText>
            }
            { errors &&
            <FormHelperText>{errors}</FormHelperText>
            }
        </FormControl>
    );
}

It renders the <CircularProgress /> on the left "fullsize":
screen shot 2017-10-30 at 10 45 18

Maybe whatever is passed along as adornment should be constrained to respect the Input height "no matter what"? I really suck at CSS so I didn't try classes overriding.

@damianobarbati What happens if you wrap the CircularProgress in an InputAdornment?

See https://github.com/callemall/material-ui/pull/8504/files#diff-3d0c58268ffed10a2bd03ed4b6799ebbR53 for an example.

@Jannis same with explicit endAdornment:

const computingAdornment = (
    <InputAdornment position={'end'}>
        <CircularProgress />
    </InputAdornment>
);

<Input
    ...
    ...
    endAdornment={computingAdornment}

It slightly moved to the top overlapping the label but still on the left :)
screen shot 2017-10-30 at 11 17 17

Ok, I thought it might be worth checking. :)

If anyone's still struggling with this, this'll fix it for you.

```
amountField: {
boxSizing: 'border-box',
},

....

fullWidth
InputProps={{
className:classes.amountField,
startAdornment: $,
}}
/>

@turbochef You should be able to remove this style in v4. It was fixed in #14988.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sys13 picture sys13  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

newoga picture newoga  路  3Comments

reflog picture reflog  路  3Comments

mattmiddlesworth picture mattmiddlesworth  路  3Comments