Текстовое поле пользовательского интерфейса материала не фокусируется в диалоговом окне пользовательского интерфейса материала - PullRequest
0 голосов
/ 07 июня 2018

Problem-

Создано диалоговое окно пользовательского интерфейса материала, которое появляется при нажатии кнопки элемента макета реагирующей сетки.Содержимое диалогового окна выберите поля и текстовые поля.Изменение выбора работает, но когда дело доходит до замены текстового поля, оно даже не фокусируется на нем.Также элемент сетки отображает перетаскиваемое поведение, когда я нажимаю на текстовое полеСобытие onchnage текстового поля сработало после нажатия клавиш клавиатуры

enter image description here

 import React from 'react';
 import {withStyles} from 'material-ui/styles'
 import PropTypes from 'prop-types';
 import Dialog, { 
    DialogActions,
    DialogContent,
    DialogContentText,
    DialogTitle,
   } from 'material-ui/Dialog';
 import Button from 'material-ui/Button';
 import TextField from 'material-ui/TextField';
 import KPISelect from './KPISelect'
 import {MenuItem} from 'material-ui/Menu';
 import {FormControl, FormHelperText} from 'material-ui/Form';
 import Select from 'material-ui/Select';
 import Input, {InputLabel} from 'material-ui/Input';

 // Inline styles for your component
 const classes = ({
 textField: {
   margin: "10px"
 },
 formControl: {
   margin: "20px"
 }
})

 // Default React Component Constructor
 class EditDialog extends React.Component {

 constructor(props) {
  super(props)
   this.state = {
     open: this.props.open,
     editableFields: this.props.editableFields,
     editValues: {}
   }
   this.buildEditableForms = this.buildEditableForms.bind(this);
 }

 componentWillReceiveProps(nxtProps) {
     let editItems= {};
     nxtProps.editableFields.forEach((item)=>{
     editItems[item.name] = item.value
     })
   this.setState({
        open: nxtProps.open,
        editableFields: nxtProps.editableFields,
        editValues: editItems
      })
   }

   handleClose = () => {
     this.props.handleClose()
   }

   buildEditableForms() {
    console.log("in editable form")
    const panels = [];
    const classes = this.props.classes;
for (let panel of this.props.editableFields) {
  let newPanel;
  if (panel.type === "text") {
    newPanel = <TextField id={panel.name} label={panel.label} className={classes.textField}
                          onChange={(event)=>this.onTextInputChanged(panel.name, event)} value={this.state.editValues[panel.name]}/>
  }
  else if(panel.type= "select"){
    const options = panel.options;
    let menuItems = options.map(i => {
      return (
        <MenuItem value={i} data-value={i}>{i}</MenuItem>
      )
    })
    newPanel =
      <FormControl className={classes.formControl}>
        <InputLabel htmlFor={panel.name}>{panel.label}</InputLabel>
        <Select
          value={this.state.editValues[panel.name]}
          onChange={this.onInputChanged}
          input={<Input name={panel.name}/>}
        >
          {menuItems}
        </Select>
        <FormHelperText>Select {panel.label} </FormHelperText>
      </FormControl>
  }
  panels.push(newPanel);
}
return panels;

  onTextInputChanged = (name, event) =>{
    console.log("changed inputs")
    let editValues = this.state.editValues
    editValues[name] = event.target.value
    this.setState({
    editValues: editValues
    })
  }

 onInputChanged = (event) => {
    let editValues = this.state.editValues
    editValues[event.target.name] = event.target.value
    this.setState({
     editValues: editValues
 })
}

 render() {
 const classes = this.props.classes;
 return (
  <Dialog open={this.state.open}
          onClose={this.handleClose}
          aria-labelledby="alert-dialog-title"
          aria-describedby="alert-dialog-description">

    <DialogTitle id="alert-dialog-title">Edit Component</DialogTitle>

    <DialogContent>
      {this.buildEditableForms()}
    </DialogContent>

    {this.props.showKPIs &&
    <KPISelect onChange={this.onKPIChange}/>
    }

    <DialogActions>

      <Button onClick={this.handleClose} color="primary">
        Cancel
      </Button>

      <Button onClick={() => this.props.onSave(this.state.editValues)} color="primary">
        Save
      </Button>

    </DialogActions>

  </Dialog>
   );
    }
  }

 // Props Validation
  EditDialog.propTypes = {
  classes: PropTypes.object
 }

// Exports the component so it is visible to other components as an import
export default withStyles(classes)(EditDialog)
...