根据特定条件,在React下拉中的残疾选项

发布于 2025-02-04 02:21:17 字数 1842 浏览 0 评论 0原文

我目前正在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:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文