我在语义ui react库中的Search In-Menu下拉菜单中苦苦挣扎 https://react.semantic-ui.com/modules/dropdown/#types-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作为参考,但此链接无济于事
答案 0 :(得分:0)
您将onChange和onBlur事件放在<Dropdown.Item>
而不是<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>