Changed model of handling key down and focus change
Этот коммит содержится в:
@@ -6,6 +6,23 @@ module.exports = React.createClass({
|
|||||||
handleClick: function() {
|
handleClick: function() {
|
||||||
this.props.handleClick(this.props.username);
|
this.props.handleClick(this.props.username);
|
||||||
},
|
},
|
||||||
|
handleKeyDown: function(e) {
|
||||||
|
var selectedMention = this.state.selectedMention <= nunMentions ? this.state.selectedMention : 1;
|
||||||
|
|
||||||
|
console.log("Here: keyDown");
|
||||||
|
|
||||||
|
if (e.key === "ArrowUp") {
|
||||||
|
//selectedMention = selectedMention === numMentions ? 1 : selectedMention++;
|
||||||
|
this.props.handleFocus(this.props.listId);
|
||||||
|
}
|
||||||
|
else if (e.key === "ArrowDown") {
|
||||||
|
//selectedMention = selectedMention === 1 ? numMentions : selectedMention--;
|
||||||
|
this.props.handleFocus(this.props.listId);
|
||||||
|
}
|
||||||
|
else if (e.key === "Enter") {
|
||||||
|
this.handleClick();
|
||||||
|
}
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var icon;
|
var icon;
|
||||||
var timestamp = UserStore.getCurrentUser().update_at;
|
var timestamp = UserStore.getCurrentUser().update_at;
|
||||||
@@ -15,7 +32,7 @@ module.exports = React.createClass({
|
|||||||
icon = <span><i className="mention-img fa fa-users fa-2x"></i></span>;
|
icon = <span><i className="mention-img fa fa-users fa-2x"></i></span>;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="mentions-name" onClick={this.handleClick}>
|
<div className="mentions-name" ref="mention" onClick={this.handleClick} onKeyDown={this.handleKeyDown}>
|
||||||
<div className="pull-left">{icon}</div>
|
<div className="pull-left">{icon}</div>
|
||||||
<div className="pull-left mention-align"><span>@{this.props.username}</span><span className="mention-fullname">{this.props.secondary_text}</span></div>
|
<div className="pull-left mention-align"><span>@{this.props.username}</span><span className="mention-fullname">{this.props.secondary_text}</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ module.exports = React.createClass({
|
|||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
PostStore.addMentionDataChangeListener(this._onChange);
|
PostStore.addMentionDataChangeListener(this._onChange);
|
||||||
|
|
||||||
|
console.log("here!");
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
$('body').on('keypress.mentionlist', '#'+this.props.id,
|
$('body').on('keypress.mentionlist', '#'+this.props.id,
|
||||||
function(e) {
|
function(e) {
|
||||||
@@ -26,6 +28,16 @@ module.exports = React.createClass({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
self.addFirstMention();
|
self.addFirstMention();
|
||||||
}
|
}
|
||||||
|
if (!self.isEmpty() && self.state.mentionText != '-1' && e.which === 38) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
self.handleFocus(0);
|
||||||
|
}
|
||||||
|
if (!self.isEmpty() && self.state.mentionText != '-1' && e.which === 40) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
self.addFirstMention(UserStore.getActiveOnlyProfiles().length - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$(document).click(function(e) {
|
$(document).click(function(e) {
|
||||||
@@ -56,21 +68,13 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
this.setState({ mentionText: '-1' });
|
this.setState({ mentionText: '-1' });
|
||||||
},
|
},
|
||||||
handleKeyDown: function(e, numMentions) {
|
handleFocus: function(listId) {
|
||||||
var selectedMention = this.state.selectedMention <= nunMentions ? this.state.selectedMention : 1;
|
console.log("here! 1");
|
||||||
|
var mention = this.refs['mention' + index];
|
||||||
// Need to be able to know number of mentions, use in conditionals & still
|
if (!mention) return;
|
||||||
// need to figure out how to highlight the mention I want every time.
|
var mentionRef = mention.refs.mention;
|
||||||
// Remember separate Mention Ref within for, second if statement in render
|
mentionRef.getDOMNode().focus();
|
||||||
// Maybe have the call there instead? Ehhh maybe not but need that to be able
|
console.log("here! 2");
|
||||||
// to "select" it maybe...
|
|
||||||
if (e.key === "ArrowUp") {
|
|
||||||
selectedMention = selectedMention === numMentions ? 1 : selectedMention++;
|
|
||||||
}
|
|
||||||
else if (e.key === "ArrowDown") {
|
|
||||||
selectedMention = selectedMention === 1 ? numMentions : selectedMention--;
|
|
||||||
}
|
|
||||||
this.setState({selectedMention: selectedMention});
|
|
||||||
},
|
},
|
||||||
addFirstMention: function() {
|
addFirstMention: function() {
|
||||||
if (!this.refs.mention0) return;
|
if (!this.refs.mention0) return;
|
||||||
@@ -140,6 +144,8 @@ module.exports = React.createClass({
|
|||||||
username={users[i].username}
|
username={users[i].username}
|
||||||
secondary_text={users[i].secondary_text}
|
secondary_text={users[i].secondary_text}
|
||||||
id={users[i].id}
|
id={users[i].id}
|
||||||
|
listId={index}
|
||||||
|
handleFocus={this.handleFocus}
|
||||||
handleClick={this.handleClick} />
|
handleClick={this.handleClick} />
|
||||||
);
|
);
|
||||||
index++;
|
index++;
|
||||||
@@ -162,7 +168,7 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mentions--top" style={style}>
|
<div className="mentions--top" style={style}>
|
||||||
<div ref="mentionlist" className="mentions-box" onKeyDown={this.handleKeyDown.bind(this, numMentions)}>
|
<div ref="mentionlist" className="mentions-box">
|
||||||
{ mentions }
|
{ mentions }
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user