fluentui下拉列表不适用于创建反应应用
我在计算机上创建了一个创建反应项目。
我在项目目录终端中运行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.
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.
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
Ive searched SO and haven't found any answers to this. Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我了解很好,您想禁用响应模式:
codepen> codepen 工作示例。
If I understand well you want to disable responsive mode:
Codepen working example.
如果您有&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).