我有一个组件,当鼠标悬停在“角色”元素上时,我想使用 Office-UI-Fabric-react 组件“标注”。
如果我引用包含“Persona”元素的“div”
(使用ref={this.setPersonaRef}
),则“Callout”有效,
但componentRef={this.setPersonaRef}
在“Persona”元素中导致
CalloutContent.componentDidMount() 中的异常:TypeError:element.getBoundingClientRect 不是函数
这是组件:
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Persona,PersonaSize } from 'office-ui-fabric-react/lib/Persona';
import { Callout } from 'office-ui-fabric-react/lib/Callout';
import {IHoverPersonaProps} from './IHoverPersonaProps';
import {IHoverPersonaState} from './IHoverPersonaState';
export default class HoverPersona extends React.Component < IHoverPersonaProps,IHoverPersonaState > {
private personaRef: any;
constructor(props) {
super(props);
this.state = {
hover: false
};
this.setPersonaRef = this.setPersonaRef.bind(this);
}
setPersonaRef(element) {
this.personaRef = element;
}
MouseEnter() {
this.setState({hover:true})
}
MouseLeave() {
this.setState({hover:false})
}
public render() : React.ReactElement < IHoverPersonaProps > {
return <div onMouseEnter={this.MouseEnter.bind(this)} onMouseLeave={this.MouseLeave.bind(this)} >
<Persona {...this.props} size={PersonaSize.extraSmall} primaryText={this.props.value} componentRef={this.setPersonaRef} />
{ this.state.hover &&
<Callout
className="ms-CalloutExample-callout"
ariaLabelledBy={'callout-label-1'}
ariaDescribedBy={'callout-description-1'}
coverTarget={false}
gapSpace={0}
target={this.personaRef}
setInitialFocus={true}
>
<div className="ms-CalloutExample-header">
<p className="ms-CalloutExample-title" id={'callout-label-1'}>
Test
</p>
</div>
<div className="ms-CalloutExample-inner">
<Persona {...this.props} size={PersonaSize.large} primaryText={this.props.value} />
</div>
</Callout>
}
</div>;
}
}
我该如何解决异常?