javascript - 无法从 Semantic-ui-react Search In-Menu Dropdown / Formik 中选择项目
问题描述
我在语义 ui 反应库 https://react.semantic-ui.com/modules/dropdown/#types-search-in-menu中的 Search In-Menu 下拉菜单中苦苦挣扎
我正在这样做
<Dropdown
name='customRoomType'
id='customRoomType'
text={values.customRoomType} //tried onchange here but not works
>
<Dropdown.Menu>
<Dropdown.Menu scrolling>
{tagOptions.map((option) => (
<Dropdown.Item key={option.value}
className={option.value}
onChange={(e, { value }) => {
{console.log('value ',value)}
setFieldValue('customRoomType', value)
}}
onBlur={handleBlur}
selectonblur={'false'}
{...option} />
))}
</Dropdown.Menu>
</Dropdown.Menu>
</Dropdown>
下拉选择不会触发任何事件处理程序
我将此React semantic-ui Dropdown onChange not working作为参考,但此链接无济于事
解决方案
您将 onChange 和 onBlur 事件置于 on<Dropdown.Item>
而不是 on<Dropdown>
试试它是否像这样工作:
<Dropdown
name='customRoomType'
id='customRoomType'
// Check here that this is the same value that you set in onChange handler.
text={values.customRoomType}
// onChange and onBlur are parts of Dropdown and not of Dropdown item
onChange={(e, { value }) => {
{console.log('value ',value)}
setFieldValue('customRoomType', value)
}}
onBlur={handleBlur}
>
<Dropdown.Menu>
<Dropdown.Menu scrolling>
{tagOptions.map((option) => (
<Dropdown.Item key={option.value}
className={option.value}
// might also be moved.
selectonblur={'false'}
{...option} />
))}
</Dropdown.Menu>
</Dropdown.Menu>
</Dropdown>
推荐阅读
- javascript - 如何在材质ui自动完成中为同一项目触发多次onChange
- javascript - 验证输入字段不为空
- javascript - 未调用一个渲染器进程/主窗口的多个 js 文件中的 ipcRenderer 侦听器
- javascript - 如何导出 WebAssembly 功能?
- python - Python 3 - 从字典列表中提取子字典值
- javascript - jQuery一键运行功能两次
- math - 使用 2d 坐标在平面上的 3d 空间中查找一个点
- angular - Angular Service Worker 更新多个域
- xpath - IMPORTXML 公式的 2 个文本之间的 Xpath
- mysql - 错误 1227 (42000):访问被拒绝;您需要(至少一个)此操作的 SUPER 特权 - 在 AWS Lightsail Mysql DB 上