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

Using a fullWidth TextField and InputAdornment messes with the input width #8825

Closed
1 task done
stefyrosca opened this issue Oct 24, 2017 · 8 comments
Closed
1 task done
Assignees
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module!

Comments

@stefyrosca
Copy link

stefyrosca commented Oct 24, 2017

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.

  • 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
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! labels Oct 24, 2017
@damianobarbati
Copy link

+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 :)

@oliviertassinari
Copy link
Member

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

@damianobarbati
Copy link

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.

@Jannis
Copy link

Jannis commented Oct 30, 2017

@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.

@damianobarbati
Copy link

damianobarbati commented Oct 30, 2017

@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

@Jannis
Copy link

Jannis commented Oct 30, 2017

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

@turbochef
Copy link

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

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

....

<TextField
  fullWidth
  InputProps={{
    className:classes.amountField,
    startAdornment: <InputAdornment position="start">$</InputAdornment>,
  }}
/>

@oliviertassinari
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

5 participants