stop using ReactDOM.findDOMNode in componentWillUnmount, use refs

This commit is contained in:
Michael Telatynski 2019-12-23 12:24:49 +00:00
parent a13ee490e8
commit 17f5849985
3 changed files with 26 additions and 12 deletions

View file

@ -38,6 +38,12 @@ module.exports = createReactClass({
// XXX resizeMethod not actually used.
resizeMethod: PropTypes.string,
defaultToInitialLetter: PropTypes.bool, // true to add default url
inputRef: PropTypes.oneOfType([
// Either a function
PropTypes.func,
// Or the instance of a DOM native element
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
]),
},
contextTypes: {
@ -148,7 +154,7 @@ module.exports = createReactClass({
const {
name, idName, title, url, urls, width, height, resizeMethod,
defaultToInitialLetter, onClick,
defaultToInitialLetter, onClick, inputRef,
...otherProps
} = this.props;
@ -171,7 +177,7 @@ module.exports = createReactClass({
if (onClick != null) {
return (
<AccessibleButton element='span' className="mx_BaseAvatar"
onClick={onClick} {...otherProps}
onClick={onClick} inputRef={inputRef} {...otherProps}
>
{ textNode }
{ imgNode }
@ -179,7 +185,7 @@ module.exports = createReactClass({
);
} else {
return (
<span className="mx_BaseAvatar" {...otherProps}>
<span className="mx_BaseAvatar" ref={inputRef} {...otherProps}>
{ textNode }
{ imgNode }
</span>
@ -188,21 +194,26 @@ module.exports = createReactClass({
}
if (onClick != null) {
return (
<AccessibleButton className="mx_BaseAvatar mx_BaseAvatar_image"
<AccessibleButton
className="mx_BaseAvatar mx_BaseAvatar_image"
element='img'
src={imageUrl}
onClick={onClick}
onError={this.onError}
width={width} height={height}
title={title} alt=""
inputRef={inputRef}
{...otherProps} />
);
} else {
return (
<img className="mx_BaseAvatar mx_BaseAvatar_image" src={imageUrl}
<img
className="mx_BaseAvatar mx_BaseAvatar_image"
src={imageUrl}
onError={this.onError}
width={width} height={height}
title={title} alt=""
ref={inputRef}
{...otherProps} />
);
}