I am trying to enter text into an input field. Some letters of the input (special latin letters) may come from button values. I created a sort of a keyboard for the special letters.
When I enter the button value into the input text, I can no longer enter any other text into the input field: it's as if it is blocked.
Here is the Button component:
class Button extends Component {
constructor() {
super();
this.onClick = this.onClick.bind(this);
}
onClick() {
this.props.handleLatinButton(this.props.letter);
}
render() {
return <button onClick={this.onClick}>{this.props.letter}</button>;
}
}
And this is the Search component:
class Search extends Component {
state = {
item: "",
value: ""
};
onChange = e => {
this.setState({ [e.target.name]: e.target.value });
};
handleLatinButton = letter => {
this.setState({ value: this.state.value + letter });
};
componentDidMount() {
this.nameInput.focus();
}
componentDidUpdate() {
this.nameInput.focus();
}
render() {
return (
<div style={searchStyle} className="card card-body mb-4 p-4">
<h6 className="display-6 text-center">Search for a customer</h6>
<form>
<div className="form-group">
<input
ref={input => {
this.nameInput = input;
}}
type="text"
className="form-control form-control-lg"
style={formStyle}
placeholder="search..."
name="item"
value={this.state.value}
onChange={this.onChange}
/>
<input
type="button"
style={buttonStyle}
className="btn btn-primary"
value="Find item"
/>
</div>
</form>
<Button letter="č" handleLatinButton={this.handleLatinButton} />
<Button letter="ḍ" handleLatinButton={this.handleLatinButton} />
<Button letter="ğ" handleLatinButton={this.handleLatinButton} />
<Button letter="ԑ" handleLatinButton={this.handleLatinButton} />
<Button letter="γ" handleLatinButton={this.handleLatinButton} />
<Button letter="ṛ" handleLatinButton={this.handleLatinButton} />
<Button letter="ṣ" handleLatinButton={this.handleLatinButton} />
<Button letter="ṭ" handleLatinButton={this.handleLatinButton} />
<Button letter="ẓ" handleLatinButton={this.handleLatinButton} />
</div>
);
}
}
How do I make the input field receive both button values and normal letters and concatenate both to form a single input value?
valueandtextin the state? - Thinker