Mention in controlled mode suggestions bug fix (#4718)

*  Mention in controlled mode suggestions bug fix

 + close #4716
This commit is contained in:
陆离 2017-01-26 12:09:26 +08:00 committed by GitHub
parent 340385d34d
commit e270fa87af

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import RcMention, { Nav, toString, toEditorState, getMentions } from 'rc-editor-mention'; import RcMention, { Nav, toString, toEditorState, getMentions } from 'rc-editor-mention';
import classNames from 'classnames'; import classNames from 'classnames';
import shallowequal from 'shallowequal';
import Icon from '../icon'; import Icon from '../icon';
export interface MentionProps { export interface MentionProps {
@ -47,10 +48,12 @@ export default class Mention extends React.Component<MentionProps, MentionState>
}; };
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps({ suggestions }) {
this.setState({ if (!shallowequal(suggestions, this.props.suggestions)) {
suggestions: nextProps.suggestions, this.setState({
}); suggestions,
});
}
} }
onSearchChange = (value) => { onSearchChange = (value) => {
@ -75,6 +78,7 @@ export default class Mention extends React.Component<MentionProps, MentionState>
suggestions: filteredSuggestions, suggestions: filteredSuggestions,
}); });
} }
onFocus = (ev) => { onFocus = (ev) => {
this.setState({ this.setState({
focus: true, focus: true,