fix: tree onRef属性不存在情况 (#3856)

This commit is contained in:
RUNZE LU 2022-03-25 17:12:49 +08:00 committed by GitHub
parent 8d4b1515fb
commit 98f3ff6b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -210,7 +210,9 @@ export class TreeSelector extends React.Component<
componentDidMount() {
const {enableNodePath} = this.props;
this.props.onRef(this)
// onRef只有渲染器的情况才会使用
this.props.onRef?.(this);
enableNodePath && this.expandLazyLoadNodes();
}

View File

@ -18,7 +18,12 @@ import {Api} from '../../types';
import {isEffectiveApi} from '../../utils/api';
import Spinner from '../../components/Spinner';
import ResultBox from '../../components/ResultBox';
import {autobind, getTreeAncestors, isMobile, createObject} from '../../utils/helper';
import {
autobind,
getTreeAncestors,
isMobile,
createObject
} from '../../utils/helper';
import {findDOMNode} from 'react-dom';
import {normalizeOptions} from '../../components/Select';
import {Action} from '../../types';
@ -127,7 +132,7 @@ export default class TreeSelectControl extends React.Component<
pathSeparator: '/'
};
treeRef: any
treeRef: any;
container: React.RefObject<HTMLDivElement> = React.createRef();
@ -417,13 +422,8 @@ export default class TreeSelectControl extends React.Component<
@autobind
handleResultChange(value: Array<Option>) {
const {
joinValues,
extractValue,
delimiter,
valueField,
multiple
} = this.props;
const {joinValues, extractValue, delimiter, valueField, multiple} =
this.props;
let newValue: any = Array.isArray(value) ? value.concat() : [];
@ -452,9 +452,12 @@ export default class TreeSelectControl extends React.Component<
async resultChangeEvent(value: any) {
const {onChange, dispatchEvent, data} = this.props;
const rendererEvent = await dispatchEvent('change', createObject(data, {
value
}));
const rendererEvent = await dispatchEvent(
'change',
createObject(data, {
value
})
);
if (rendererEvent?.prevented) {
return;