fluentui下拉列表不适用于创建反应应用

发布于 2025-02-13 03:45:59 字数 1899 浏览 0 评论 0原文

我在计算机上创建了一个创建反应项目。

我在项目目录终端中运行npm i @fluentui/react以安装流利的UI软件包。

我有简单的代码显示下拉列表,所有正确的导入都

import { Dropdown, DropdownMenuItemType, IDropdownStyles, IDropdownOption } from '@fluentui/react/lib/Dropdown';

const dropdownStyles: Partial<IDropdownStyles> = {
  dropdown: { width: 300 },
};

const options: IDropdownOption[] = [
  { key: 'fruitsHeader', text: 'Fruits', itemType: DropdownMenuItemType.Header },
  { key: 'apple', text: 'Apple' },
  { key: 'banana', text: 'Banana' },
  { key: 'orange', text: 'Orange', disabled: true },
  { key: 'grape', text: 'Grape' },
  { key: 'divider_1', text: '-', itemType: DropdownMenuItemType.Divider },
  { key: 'vegetablesHeader', text: 'Vegetables', itemType: DropdownMenuItemType.Header },
  { key: 'broccoli', text: 'Broccoli' },
  { key: 'carrot', text: 'Carrot' },
  { key: 'lettuce', text: 'Lettuce' },
];

function App() {
  return (
    <div className="App">
     <Dropdown
        placeholder="Select an option"
        options={options}
        styles={dropdownStyles}
      />
    </div>
  );
}

显示的是一个奇怪的框,没有可单击的下拉列表。

我进行了一些研究,需要导入图标,因此我在项目中添加了此类代码。

import { initializeIcons } from "@fluentui/react/lib/Icons";

initializeIcons();

现在,下拉列表显示了正确的图标,但是没有发生任何图标。

奇怪的是,当屏幕尺寸为平板电脑尺寸时,下拉台将显示为上下文窗格,但不会显示以全屏模式出现

ive搜索了,但尚未找到任何答案。任何帮助将不胜感激!

I created a create-react-app project on my machine.

I ran npm i @fluentui/react in my project directory terminal to install the fluent ui package.

I have simple code to display a dropdown, with all the correct imports

import { Dropdown, DropdownMenuItemType, IDropdownStyles, IDropdownOption } from '@fluentui/react/lib/Dropdown';

const dropdownStyles: Partial<IDropdownStyles> = {
  dropdown: { width: 300 },
};

const options: IDropdownOption[] = [
  { key: 'fruitsHeader', text: 'Fruits', itemType: DropdownMenuItemType.Header },
  { key: 'apple', text: 'Apple' },
  { key: 'banana', text: 'Banana' },
  { key: 'orange', text: 'Orange', disabled: true },
  { key: 'grape', text: 'Grape' },
  { key: 'divider_1', text: '-', itemType: DropdownMenuItemType.Divider },
  { key: 'vegetablesHeader', text: 'Vegetables', itemType: DropdownMenuItemType.Header },
  { key: 'broccoli', text: 'Broccoli' },
  { key: 'carrot', text: 'Carrot' },
  { key: 'lettuce', text: 'Lettuce' },
];

function App() {
  return (
    <div className="App">
     <Dropdown
        placeholder="Select an option"
        options={options}
        styles={dropdownStyles}
      />
    </div>
  );
}

What is getting displayed is a weird box with no clickable dropdown.
enter image description here

I did some research and I needed to import the icons so I added such code to my project.

import { initializeIcons } from "@fluentui/react/lib/Icons";

initializeIcons();

Now the dropdown displays the correct icon however nothing happens onclick of the icon.
enter image description here

Weirdly enough, when the screen size is tablet sized the dropdown will show up as context pane but will not appear in full screen mode
enter image description here

Ive searched SO and haven't found any answers to this. Any help would be appreciated!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你又不是我 2025-02-20 03:45:59

如果我了解很好,您想禁用响应模式:

import { ResponsiveMode } from '@fluentui/react'

<Dropdown
  ...
  responsiveMode={ResponsiveMode.unknown}
/>

codepen> codepen 工作示例。

If I understand well you want to disable responsive mode:

import { ResponsiveMode } from '@fluentui/react'

<Dropdown
  ...
  responsiveMode={ResponsiveMode.unknown}
/>

Codepen working example.

池予 2025-02-20 03:45:59

如果您有&lt; react.strictmode&gt;在您的index.tsx中,您可以删除此操作,然后可以使用(至少在我遇到同样的问题时)。

If you have <React.StrictMode> in your index.tsx, you can remove this and then it works (at least for me when I was having the same issue).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文