reactjs - 带有反应选择的焦点小组
问题描述
我正在使用来自 react-select using groups 的自定义 Select 元素。用户应该能够使用箭头键浏览选项。这适用于选项,但不适用于组,因为当用户使用箭头键浏览选项时会跳过组(参见示例)。
由于用户应该能够与 grouplabel 中的复选框进行交互,因此允许使用键盘在选项和组中导航会很好。这是受支持的功能还是有人试图实现这种行为?
例子
用户界面
代码
import Select, {GroupTypeBase} from 'react-select'
interface SelectOption {
label: string,
value: string
}
export const GroupedSelect = () => {
return <Select
options={getOptions()}
isSearchable={true}
isMulti={true}
formatGroupLabel={formatLabel}
formatOptionLabel={formatLabel}
/>
}
const formatLabel = (group: GroupTypeBase<any>) => {
return <div>
<input type={"checkbox"}/>
{group.label}
</div>
}
const getOptions: () => GroupTypeBase<SelectOption>[] = () => {
return [
{
label: "Foo Group",
options: createGroupSelectOptions("Foo")
},
{
label: "Bar Group",
options: createGroupSelectOptions("Bar")
},
{
label: "Baz Group",
options: createGroupSelectOptions("Baz")
},
]
}
const createGroupSelectOptions: (groupName: string, groupSize?: number) => SelectOption[] = (groupName: string, groupSize = 3) => {
const ary = new Array(groupSize).fill("").map((_, idx) => {
return {
label: `${groupName} ${idx}`, value: `${groupName} ${idx}`
}
})
console.log(ary)
return ary
}
解决方案
推荐阅读
- javascript - 如何找到数组元素的索引?
- c++ - 标头的虚拟方法在g ++编译期间出错
- r - 有条件地过滤重复的行
- r - 仪表板在闪亮的应用程序中工作,但不在 flexdashboard 上
- batch-file - 如何通过 Batch-Vbscript 混合脚本获取新生成进程的窗口标题?
- javascript - 在对象中查找空值和 null 值并在计数器 javascript 中更新
- javascript - Javascript:如何连接 2 个值,将未定义或空值视为空
- botframework - Cognito 在 OAuth2 身份提供者中授权端点
- javascript - javascript - laravel 重置表单
- java - java - 如何在java中以原子方式将多个文件从src复制到dest?