Changed SuggestionBox to clear suggestions shortly after losing focus (#4721)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
65699c7c51
Коммит
c2be6497eb
@@ -12,6 +12,10 @@ import {FormattedMessage} from 'react-intl';
|
|||||||
import {Popover} from 'react-bootstrap';
|
import {Popover} from 'react-bootstrap';
|
||||||
|
|
||||||
export default class SearchSuggestionList extends SuggestionList {
|
export default class SearchSuggestionList extends SuggestionList {
|
||||||
|
static propTypes = {
|
||||||
|
...SuggestionList.propTypes
|
||||||
|
};
|
||||||
|
|
||||||
getContent() {
|
getContent() {
|
||||||
return $(ReactDOM.findDOMNode(this.refs.popover)).find('.popover-content');
|
return $(ReactDOM.findDOMNode(this.refs.popover)).find('.popover-content');
|
||||||
}
|
}
|
||||||
@@ -92,7 +96,3 @@ export default class SearchSuggestionList extends SuggestionList {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchSuggestionList.propTypes = {
|
|
||||||
...SuggestionList.propTypes
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
import $ from 'jquery';
|
|
||||||
|
|
||||||
import Constants from 'utils/constants.jsx';
|
import Constants from 'utils/constants.jsx';
|
||||||
import * as GlobalActions from 'actions/global_actions.jsx';
|
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||||
import SuggestionStore from 'stores/suggestion_store.jsx';
|
import SuggestionStore from 'stores/suggestion_store.jsx';
|
||||||
@@ -18,7 +16,7 @@ export default class SuggestionBox extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.handleDocumentClick = this.handleDocumentClick.bind(this);
|
this.handleBlur = this.handleBlur.bind(this);
|
||||||
|
|
||||||
this.handleCompleteWord = this.handleCompleteWord.bind(this);
|
this.handleCompleteWord = this.handleCompleteWord.bind(this);
|
||||||
this.handleChange = this.handleChange.bind(this);
|
this.handleChange = this.handleChange.bind(this);
|
||||||
@@ -36,8 +34,6 @@ export default class SuggestionBox extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
$(document).on('click', this.handleDocumentClick);
|
|
||||||
|
|
||||||
SuggestionStore.addCompleteWordListener(this.suggestionId, this.handleCompleteWord);
|
SuggestionStore.addCompleteWordListener(this.suggestionId, this.handleCompleteWord);
|
||||||
SuggestionStore.addPretextChangedListener(this.suggestionId, this.handlePretextChanged);
|
SuggestionStore.addPretextChangedListener(this.suggestionId, this.handlePretextChanged);
|
||||||
}
|
}
|
||||||
@@ -55,7 +51,6 @@ export default class SuggestionBox extends React.Component {
|
|||||||
SuggestionStore.removePretextChangedListener(this.suggestionId, this.handlePretextChanged);
|
SuggestionStore.removePretextChangedListener(this.suggestionId, this.handlePretextChanged);
|
||||||
|
|
||||||
SuggestionStore.unregisterSuggestionBox(this.suggestionId);
|
SuggestionStore.unregisterSuggestionBox(this.suggestionId);
|
||||||
$(document).off('click', this.handleDocumentClick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getTextbox() {
|
getTextbox() {
|
||||||
@@ -72,18 +67,11 @@ export default class SuggestionBox extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDocumentClick(e) {
|
handleBlur() {
|
||||||
if (!SuggestionStore.hasSuggestions(this.suggestionId)) {
|
setTimeout(() => {
|
||||||
return;
|
// Delay this slightly so that we don't clear the suggestions before we run click handlers on SuggestionList
|
||||||
}
|
|
||||||
|
|
||||||
const container = $(this.refs.container);
|
|
||||||
|
|
||||||
if (!(container.is(e.target) || container.has(e.target).length > 0)) {
|
|
||||||
// We can't just use blur for this because it fires and hides the children before
|
|
||||||
// their click handlers can be called
|
|
||||||
GlobalActions.emitClearSuggestions(this.suggestionId);
|
GlobalActions.emitClearSuggestions(this.suggestionId);
|
||||||
}
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(e) {
|
handleChange(e) {
|
||||||
@@ -214,6 +202,7 @@ export default class SuggestionBox extends React.Component {
|
|||||||
|
|
||||||
const childProps = {
|
const childProps = {
|
||||||
ref: 'textbox',
|
ref: 'textbox',
|
||||||
|
onBlur: this.handleBlur,
|
||||||
onInput: this.handleChange,
|
onInput: this.handleChange,
|
||||||
onCompositionStart: this.handleCompositionStart,
|
onCompositionStart: this.handleCompositionStart,
|
||||||
onCompositionUpdate: this.handleCompositionUpdate,
|
onCompositionUpdate: this.handleCompositionUpdate,
|
||||||
|
|||||||
@@ -10,6 +10,16 @@ import {FormattedMessage} from 'react-intl';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export default class SuggestionList extends React.Component {
|
export default class SuggestionList extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
suggestionId: React.PropTypes.string.isRequired,
|
||||||
|
location: React.PropTypes.string,
|
||||||
|
renderDividers: React.PropTypes.bool
|
||||||
|
};
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
renderDividers: false
|
||||||
|
};
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@@ -65,7 +75,7 @@ export default class SuggestionList extends React.Component {
|
|||||||
|
|
||||||
scrollToItem(term) {
|
scrollToItem(term) {
|
||||||
const content = this.getContent();
|
const content = this.getContent();
|
||||||
if (!content) {
|
if (!content || content.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,13 +163,3 @@ export default class SuggestionList extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SuggestionList.propTypes = {
|
|
||||||
suggestionId: React.PropTypes.string.isRequired,
|
|
||||||
location: React.PropTypes.string,
|
|
||||||
renderDividers: React.PropTypes.bool
|
|
||||||
};
|
|
||||||
|
|
||||||
SuggestionList.defaultProps = {
|
|
||||||
renderDividers: false
|
|
||||||
};
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user