Material-ui: InputAdornment focused state

Created on 29 Apr 2018  路  1Comment  路  Source: mui-org/material-ui


There seem to be no way for an InputAdornment to know if it's inside a focused Input or FormControl.

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

Expected Behavior


I followed the pattern in FormLabel to try to get muiFormControl from the context and then assigning a class when muiFormControl.focused is true.

Current Behavior


context.muiFormControl is undefined

Steps to Reproduce (for bugs)


See example at: https://codesandbox.io/s/k2vl243823

Context


I am trying to implement an adornment that's only visible when the Input is focused.

Your Environment

| Tech | Version |
|--------------|---------|
| Material-UI |1.0.0-beta.43 |
| React | 16.2.0 |
| browser | all|
| etc | |

>All comments

@ErikDakoda context.muiFormControl is an implementation detail. Don't use it.
I would say that the best approach is the following:

          <Input
            onFocus={() => {
              this.setState({
                focused: true
              });
            }}
            onBlur={() => {
              this.setState({
                focused: false
              });
            }}
            endAdornment={<EndAdornment focused={this.state.focused} />}
          />

https://codesandbox.io/s/vv758ylxn0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rbozan picture rbozan  路  3Comments

sys13 picture sys13  路  3Comments

newoga picture newoga  路  3Comments

reflog picture reflog  路  3Comments

mb-copart picture mb-copart  路  3Comments