[英]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. 基本上有两种方法可以做到这一点。
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 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, }]
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 const farItems = [ { key: 'persona', name: 'Persona', commandBarButtonAs: PersonaCommandBarComponent } ]; function PersonaCommandBarComponent() { return ( ); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.