Вот ссылка на материал-Ui шаговых: http://www.material-ui.com/#/components/stepperМатериал-УИ: текстовые поля внутри шаговых не принимает их defaultValues правильно
Я пытаюсь использовать три этапа шагового, на каждом этапе у меня есть материал-щ текстовое поле с заданным значением по умолчанию.
На шаге 1 я могу видеть, что значение по умолчанию для текстовых полей указано как Initial title value
, но последующие шаги не соответствуют их предоставленным значениям по умолчанию, вместо этого они отображают Initial title value
как их значение по умолчанию. В то время как текст заголовка и флотирования изменяется, их значение по умолчанию берется из шага 1, почему так?
import React from 'react';
import {
Step,
Stepper,
StepLabel,
} from 'material-ui/Stepper';
import RaisedButton from 'material-ui/RaisedButton';
import FlatButton from 'material-ui/FlatButton';
/**
* Horizontal steppers are ideal when the contents of one step depend on an earlier step.
* Avoid using long step names in horizontal steppers.
*
* Linear steppers require users to complete one step in order to move on to the next.
*/
class HorizontalLinearStepper extends React.Component {
state = {
finished: false,
stepIndex: 0,
};
handleNext =() => {
const {stepIndex} = this.state;
this.setState({
stepIndex: stepIndex + 1,
finished: stepIndex >= 2,
});
};
handlePrev =() => {
const {stepIndex} = this.state;
if (stepIndex > 0) {
this.setState({stepIndex: stepIndex - 1});
}
};
getStepContent(stepIndex) {
switch (stepIndex) {
case 0:
return (
<TextField
id="1"
hintText="Title"
floatingLabelText="Title"
type="text"
ref = "title"
errorText= {errors.title}
fullWidth={true}
defaultValue="Initial title value"
/>
);
case 1:
return (
<TextField
id="2"
hintText="Description"
floatingLabelText="description"
type="text"
ref = "description"
errorText= {errors.description}
fullWidth={true}
defaultValue="Initial description value"
/>
);
case 2:
return (
<TextField
id="3"
hintText="Name"
floatingLabelText="name"
type="text"
ref = "name"
errorText= {errors.name}
fullWidth={true}
defaultValue="Initial name value"
/>
);
default:
return 'You\'re a long way from home sonny jim!';
}
}
render() {
const {finished, stepIndex} = this.state;
const contentStyle = {margin: '0 16px'};
return (
<div style={{width: '100%', maxWidth: 700, margin: 'auto'}}>
<Stepper activeStep={stepIndex}>
<Step>
<StepLabel>Select campaign settings</StepLabel>
</Step>
<Step>
<StepLabel>Create an ad group</StepLabel>
</Step>
<Step>
<StepLabel>Create an ad</StepLabel>
</Step>
</Stepper>
<div style={contentStyle}>
{finished ? (
<p>
<a
href="#"
onClick={(event) => {
event.preventDefault();
this.setState({stepIndex: 0, finished: false});
}}
>
Click here
</a> to reset the example.
</p>
) : (
<div>
<p>{this.getStepContent(stepIndex)}</p>
<div style={{marginTop: 12}}>
<FlatButton
label="Back"
disabled={stepIndex === 0}
onTouchTap={this.handlePrev}
style={{marginRight: 12}}
/>
<RaisedButton
label={stepIndex === 2 ? 'Finish' : 'Next'}
primary={true}
onTouchTap={this.handleNext}
/>
</div>
</div>
)}
</div>
</div>
);
}
}
export default HorizontalLinearStepper;
Это выглядит отлично, но что, если у нас есть количество текстовых полей на каждом шаге. Вы порекомендовали бы держать обработчик изменения состояния для каждого из них? – nitte93user3232918