我正在尝试在应用程序中使用Fabric react messageBar组件,但是即使我单击messageBar组件中的关闭图标,也无法关闭(关闭)消息部分。
请找到以下代码以供参考。
import React from 'react'
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib-commonjs/MessageBar'
class MyMessage extends React.Component{
log=(event)=>{
console.log('close on test');
}
render(){
return(
<div>
<MessageBar
componentRef={(messageBar)=>{this.errorMsgBar = messageBar}}
messageBarType={MessageBarType.error}
isMultiline={false}
onDismiss={(event)=> this.log(event)}
dismissButtonAriaLabel="Close"
>
Error lorem ipsum dolor sit amet, a elit sem interdum consectetur adipiscing elit.{' '}
</MessageBar>
</div>
)
}
}
export default MyMessage;
Office Fabric将默认关闭功能,还是我需要关闭它?
如果我需要关闭它,请让我知道我们该怎么做?
提前谢谢。
-Nagaraju
答案 0 :(得分:3)
您可以尝试以下操作:
import React from 'react'
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib-commonjs/MessageBar'
class MyMessage extends React.Component{
constructor(){
super();
this.state = {
showMessageBar: true
}
}
closeMessageBar = () => {
this.setState({showMessageBar: false})
}
render(){
return(
<div>
{this.state.showMessageBar && <MessageBar
componentRef={(messageBar)=>{this.errorMsgBar = messageBar}}
messageBarType={MessageBarType.error}
isMultiline={false}
onDismiss={()=> this.closeMessageBar()}
dismissButtonAriaLabel="Close"
>
Error lorem ipsum dolor sit amet, a elit sem interdum consectetur adipiscing elit.{' '}
</MessageBar>}
</div>
)
}
}
export default MyMessage;