1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| import React, { Component, Fragment } from 'react'; import Combobox from './components/Combobox'
class Container extends Component { constructor(props) { super(props); this.childRef = React.createRef(); this.state = { message: '', placeholder: '', showMessageList: false, isDisabled: true, options: [] } } componentDidMount () { this.setState({ placeholder: '응원하세요.', options: [ '직접 입력하기', '여러분 힘내세요.', '응원합니다.' ] }) } componentDidUpdate () { if(this.state.placeholder === '직접 입력하기') { this.childRef.current.focus(); } } onClick = () => { this.setState({ showMessageList: true }) } onClickMessage = (e) => { const messageSelected = e.target.innerText; if(messageSelected === '직접 입력하기') { this.setState({ message: '', placeholder: messageSelected, isDisabled: false, showMessageList: false }) return; } this.setState({ message: e.target.innerText, showMessageList: false, placeholder: '응원 메세지 작성 혹은 선택해주세요.' }) } onChange = (e) => { if(this.state.placeholder === '직접 입력하기') { this.setState({ message: e.target.value, showMessageList: false }) } } onBlur = () => { this.setState({ showMessageList: false }) } render() { const { message, placeholder, showMessageList, isDisabled, options } = this.state; return ( <Fragment> <Combobox message={message} placeholder={placeholder} showMessageList={showMessageList} isDisabled={isDisabled} options={options} ref={this.childRef} onClick={this.onClick} onClickMessage={this.onClickMessage} onChange={this.onChange} onBlur={this.onBlur} /> </Fragment> ); } }
export default Container;
|