简体   繁体   English

如何在React Fabric-UI的CommandBar中显示Persona组件?

[英]How can I display a Persona component in a CommandBar in React Fabric-UI?

I am trying to display a Persona component on the far right of my CommandBar component, which I use as a header for my application. 我试图在CommandBar组件的最右边显示一个Persona组件,该组件用作应用程序的标题。

Here's a code snippet 这是一个代码片段

const getFarItems = () => {
  return [
    {
      key: 'profile',
      text: <Persona text="Kat Larrson" />,
      onClick: () => console.log('Sort')
    }
  ]
}


const FabricHeader: React.SFC<props> = () => {
  return (
    <div>
      <CommandBar
        items={getItems()}
        farItems={getFarItems()}
        ariaLabel={'Use left and right arrow keys to navigate between commands'}
      />
    </div>
  );
}

This throws a type error because the text prop expects a string and not a component. 这会引发类型错误,因为text属性需要字符串而不是组件。 Any help would be appreciated! 任何帮助,将不胜感激!

Under the ICommandBarItemProps there is a property called commandBarButtonAs that the docs state: 根据ICommandBarItemProps有一个叫做财产commandBarButtonAs文档状态:

Method to override the render of the individual command bar button. 重写单个命令栏按钮的呈现的方法。 Note, is not used when rendered in overflow 注意,在溢出时不使用

And its default component is CommandBarButton which is basically a Button 它的默认组件是CommandBarButton ,它基本上是一个Button

Basically there are two ways to do this. 基本上有两种方法可以做到这一点。

  1. Keep using Button, and apply your own renderer. 继续使用Button,然后应用您自己的渲染器。 Basically the IButtonProps you can add onRenderChildren which would allow you to add any Component such as Persona to render. 基本上,可以在IButtonProps上添加onRenderChildren ,它允许您添加要渲染的任何组件(例如Persona)。 This example would show you how it is done https://codepen.io/micahgodbolt/pen/qMoYQo 此示例将向您展示如何完成此操作https://codepen.io/micahgodbolt/pen/qMoYQo
const farItems = [{
    // Set to null if you have submenus that want to hide the down arrow.
    onRenderMenuIcon: () => null, 
    // Any renderer
    onRenderChildren: () => ,
    key: 'persona',
    name: 'Persona',
    iconOnly: true,
}]
  1. Or add your own crazy component not dependent on CommandBarButton but that means you need to handle everything like focus, accessibility yourself. 或添加您自己的不依赖CommandBarButton的疯狂组件,但这意味着您需要自己处理所有内容,例如焦点,可访问性。 This example would show you how it is done https://codepen.io/mohamedhmansour/pen/GPNKwM 此示例将向您展示如何完成此操作https://codepen.io/mohamedhmansour/pen/GPNKwM
const farItems = [
  {
    key: 'persona',
    name: 'Persona',
    commandBarButtonAs: PersonaCommandBarComponent
  }
];

function PersonaCommandBarComponent() {
  return (
    
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Office Fabric UI React 中将 ContextualMenu 与 Persona 结合使用? - How can you use ContextualMenu with Persona in Office Fabric UI React? 如何使用 Office UI Fabric React 在 CommandBar 菜单中显示喙? - How to show beaks in CommandBar menus with Office UI Fabric React? 更新行时如何刷新Fabric-U的DetailsList - How to refresh Fabric-Ui DetailsList when updating a row 如何在Office UI Fabric React图标按钮组件中使用“真棒字体”图标? - How can I use Font Awesome icons in an Office UI Fabric React icon button component? Office Fluent UI / Fabric UI Modal - 如何从正文组件中关闭它? - Office Fluent UI / Fabric UI Modal - how can I close it from the body component? 如何在react ui-fabric 库中自定义GroupedList 组件中的标头 - How to customize the header in GroupedList component in react ui-fabric library 将项目推送到流畅的 ui 命令栏组件 - Push items to fluent ui commandbar component 我如何使用导出导出material -ui组件 - How can I export a react material-ui component with 如何在 React 的 UI 组件中为变量赋值? - How can I assign value to a variable inside a UI component in React? 反应样式/组件未显示(MS Fabric UI) - React styling/component not showing (MS Fabric UI)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM