Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting material-ui components to appear inline by overriding style props

I am trying to get a check box to appear to the right of the input field "answer input one" I have tried playing with the display property but am really struggling with css layouts in general.what I am currently getting

Here is the code that is rendering the answer input:

     <div>
  <TextField
  hintText="An informative question title..."
  fullWidth
  floatingLabelText="Question Title"
  value={questionTitle}
  onChange={(e) => this.props.questionTitleChanged(e.target.value)}
  />
  <TextField
  floatingLabelText="Answer Input 1"
  onChange={(e) => this.props.questionInputChanged({
    inputIndex: 0,
    value: e.target.value,
    correct: false
  })}
  value={questionInputs[0].value}
  style={styles.answerField}
  />

  <Checkbox
  onCheck={() => {
    let correctOrIncorrect = null;

    if (questionInputs[0].correct) {
      correctOrIncorrect = false;
    } else { correctOrIncorrect = true; }

    this.props.questionInputChanged({
    inputIndex: 0,
    value: null,
    correct: correctOrIncorrect });
  }}
  style={styles.checkbox}
  />

  </div>

And the inline styles are here:

const styles = {
  createQuizContainer: {
    width: '70%',
    margin: 'auto',
    paddingTop: 30,
    paddingBottom: 40
  },
  answerField: {
    width: '70%',
  },
  checkBox: {
    display: 'inline',
  }

};

and help would be greatly appreciated! As well as any advice on layouts with css in general!

Thanks.

like image 310
LuckyLukas Avatar asked Jan 26 '17 12:01

LuckyLukas


People also ask

How do you override styles in material UI?

To override the styles of a specific part of the component, use the global classes provided by Material UI, as described in the previous section "Overriding nested component styles" under the sx prop section.

Is Tailwind better than material UI?

Consider Material UI if you are an avid React user and don't have the time to build a custom UI from scratch. Consider Tailwind CSS if you want to build a custom UI within your markup while writing minimal custom css.


1 Answers

You could use flexbox:

render() {
    return (
        <div style={{ display: 'inline-flex' }}>
            <div>
                <TextField />
            </div>
            <div style={{ alignSelf: 'center' }}>
                <Checkbox />
            </div>
        </div>
    );
}

https://jsfiddle.net/2v1Legy2/1/

like image 165
Jeff McCloud Avatar answered Oct 02 '22 22:10

Jeff McCloud