根据特定条件,在React下拉中的残疾选项
我目前正在React中建立下拉组件。它已经工作正常 - 我现在只想在发生特定条件时才禁用一些选项。在这种情况下,我有两个下拉列表可用作滤波器系统。第一个是“从” - 滤波器,第二个a”到“ - 滤波器。如果您在“ from” -dropdown中选择一个选项,我希望“ to” dropdown禁用所选和所有以前的选项。
这是我的代码:
import {
Dropdown,
IDropdownStyles,
IDropdownOption,
} from "@fluentui/react";
interface DropdownProps {
options: IDropdownOption[],
placeholder: string,
setDropdown: Dispatch<SetStateAction<string>>
}
const dropwdownStyles: Partial<IDropdownStyles> = {
dropdown: { width: 300 },
};
export const DropdownId = (props: DropdownProps) => {
return (
<div className={styles.root}>
<Dropdown
placeholder={props.placeholder}
options={props.options}
styles={dropwdownStyles}
onChange={(e, options) => {
props.setDropdown(`${options?.key}`)
}}
/>
</div>
);
};
在index.tsx中实现下拉列表:
<Container>
<DropdownId options={apiTagsResponse.map(tag => ({ text: tag, key: tag }))} setDropdown={setStartObjectId} placeholder="Set Start Tag" />
</Container>
<Container>to</Container>
<Container>
<DropdownId options={apiTagsResponse.map(tag => ({ text: tag, key: tag }))} setDropdown={setEndObjectId} placeholder="Set End Tag" />
</Container>
<Container>
<DropdownApplyFilterButton onClick={() => setButtonClicked(true)} />
</Container>
结果:
I am currently building a dropdown component in react. It already works fine - I now would like to have some options disabled only when a specific condition occurs. In this case I have two dropdowns which work as a filter system. The first is a "from"-filter and the second a "to"-filter. If you select an option in the "from"-dropdown, I'd like the "to"-dropdown to disable the selected and all previous options.
This is my code:
import {
Dropdown,
IDropdownStyles,
IDropdownOption,
} from "@fluentui/react";
interface DropdownProps {
options: IDropdownOption[],
placeholder: string,
setDropdown: Dispatch<SetStateAction<string>>
}
const dropwdownStyles: Partial<IDropdownStyles> = {
dropdown: { width: 300 },
};
export const DropdownId = (props: DropdownProps) => {
return (
<div className={styles.root}>
<Dropdown
placeholder={props.placeholder}
options={props.options}
styles={dropwdownStyles}
onChange={(e, options) => {
props.setDropdown(`${options?.key}`)
}}
/>
</div>
);
};
Implementing the dropdown in index.tsx:
<Container>
<DropdownId options={apiTagsResponse.map(tag => ({ text: tag, key: tag }))} setDropdown={setStartObjectId} placeholder="Set Start Tag" />
</Container>
<Container>to</Container>
<Container>
<DropdownId options={apiTagsResponse.map(tag => ({ text: tag, key: tag }))} setDropdown={setEndObjectId} placeholder="Set End Tag" />
</Container>
<Container>
<DropdownApplyFilterButton onClick={() => setButtonClicked(true)} />
</Container>
The result:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论