【发布时间】:2021-09-13 11:21:34
【问题描述】:
在一个 antd React 项目中,我有一个带有某些值的下拉列表。我的意图是在选择特定选项时切换文本框。考虑以下代码示例
import { Input } from 'antd';
const { Option } = Select;
const { TextArea } = Input;
// const [inputBox, setInputBox] = useState(false)
function onChange(value) {
{/* if(value == "Lucy") {
setInputBox(true)
} */}
}
ReactDOM.render(
<Select
showSearch
style={{ width: 200 }}
placeholder="Select a person"
optionFilterProp="children"
onChange={onChange}
filterOption={(input, option) =>
option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
<Option value="tom">Tom</Option>
</Select>,
{/* Here I need to create a TextBox on selecting 'lucy', and dismissed on selection of other option */}
{
inputBox ? (<TextArea placeholder="Lucy Text" rows={3} />)
}
document.getElementById("container")
);
这里是 Codesandbox 链接:https://codesandbox.io/s/select-with-search-field-antd-4-17-0-alpha-0-forked-9qeq9
我无法创建该输入框。任何适当的解决方案都受到高度赞赏
【问题讨论】: