Skip to content

Commit

Permalink
fix bug -- update in The To dropdown list should be supported keyboar…
Browse files Browse the repository at this point in the history
…d operation (#143)

* update in The To dropdown list should be supported keyboard operation

* remove items judgement from contactdropdownlist to recipientinput

* remove items judgement from contactdropdownlist to recipientinput

* fix bug that selectedcontactindex will be bigger than relatedContactList.length
  • Loading branch information
sophiewu2333 authored and embbnux committed Mar 28, 2017
1 parent 543fe75 commit 039d63a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/components/ContactDropdownList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ ContactItem.propTypes = {
};

function ContactDropdownList(props) {
let items = props.items;
// MAX 5
if (items.length > 5) {
items = items.slice(0, 5);
}
const items = props.items;
let listClassName = null;
let hiddenClassName = null;
if (items.length === 0 || !props.visibility) {
Expand Down Expand Up @@ -93,8 +89,8 @@ ContactDropdownList.propTypes = {
})).isRequired,
formatContactPhone: PropTypes.func.isRequired,
addToRecipients: PropTypes.func.isRequired,
active: PropTypes.bool.isRequired,
setSelectedIndex: PropTypes.func.isRequired,
selectedIndex: PropTypes.number.isRequired,
};

ContactDropdownList.defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessageList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class MessageList extends Component {
const totalScrollHeight = this.messagesListBody.scrollHeight;
const clientHeight = this.messagesListBody.clientHeight;
currentScrollHeight = this.messagesListBody.scrollTop;
// loadNextPageMessages if srroll near buttom
// loadNextPageMessages if scroll near buttom
if (
(totalScrollHeight - lastScrollHeight) > (clientHeight + 10) &&
(totalScrollHeight - currentScrollHeight) <= (clientHeight + 10)
Expand Down
29 changes: 21 additions & 8 deletions src/components/RecipientsInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class RecipientsInput extends Component {
};

this.addSelectedContactIndex = () => {
if (this.state.selectedContactIndex >= (this.props.searchContactList.length - 1)) {
const length = this.props.searchContactList.length < 5 ?
this.props.searchContactList.length : 5;
if (this.state.selectedContactIndex >= (length - 1)) {
this.setState({
selectedContactIndex: 0,
});
Expand All @@ -93,14 +95,16 @@ class RecipientsInput extends Component {
};

this.reduceSelectedContactIndex = () => {
if (this.state.selectedContactIndex >= (this.props.searchContactList.length - 1)) {
this.setState({
selectedContactIndex: (this.props.searchContactList.length - 1),
});
} else {
const length = this.props.searchContactList.length < 5 ?
this.props.searchContactList.length : 5;
if (this.state.selectedContactIndex > 0) {
this.setState(preState => ({
selectedContactIndex: (preState.selectedContactIndex - 1),
}));
} else {
this.setState({
selectedContactIndex: (length - 1),
});
}
};

Expand All @@ -121,8 +125,12 @@ class RecipientsInput extends Component {
if (this.props.value.length === 0) {
return;
}
const relatedContactList = this.props.value.length >= 3 ?
let relatedContactList = this.props.value.length >= 3 ?
this.props.searchContactList : [];
// MAX 5
if (relatedContactList.length > 5) {
relatedContactList = relatedContactList.slice(0, 5);
}
const currentSelected
= relatedContactList[this.state.selectedContactIndex];
if (currentSelected) {
Expand All @@ -143,12 +151,17 @@ class RecipientsInput extends Component {
}

render() {
const relatedContactList = this.props.value.length >= 3 ?
let relatedContactList = this.props.value.length >= 3 ?
this.props.searchContactList : [];
const label = this.props.label ?
(
<label>{this.props.label}</label>
) : null;
// MAX 5
if (relatedContactList.length > 5) {
relatedContactList = relatedContactList.slice(0, 5);
}

return (
<div className={styles.container} onKeyDown={this.handleHotKey}>
{label}
Expand Down

0 comments on commit 039d63a

Please sign in to comment.