Skip to content

Commit

Permalink
FIX (keybord navigation): fix jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
sanusart committed Mar 3, 2019
1 parent 65046a5 commit aa05354
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ class Item extends Component {

componentDidUpdate() {
if (this.props.state.cursor === this.props.itemIndex) {
this.item.current && this.item.current.scrollIntoView(false);
this.item.current &&
this.item.current.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
}
}

render() {
const { props, state, methods, item, itemIndex } = this.props;
const { props, state, methods, item, itemIndex } = this.props;

if (props.itemRenderer) {
return props.itemRenderer({ item, itemIndex, props, state, methods });
Expand All @@ -36,9 +37,9 @@ class Item extends Component {
tabIndex="-1"
className={`${LIB_NAME}-item ${
methods.isSelected(item) ? `${LIB_NAME}-item-selected` : ''
} ${state.cursor === itemIndex ? `${LIB_NAME}-item-active` : ''} ${
} ${state.cursor === itemIndex ? `${LIB_NAME}-item-active` : ''} ${
item.disabled ? `${LIB_NAME}-item-disabled` : ''
}`}
}`}
onClick={item.disabled ? undefined : () => methods.addItem(item)}
onKeyPress={item.disabled ? undefined : () => methods.addItem(item)}
color={props.color}>
Expand All @@ -54,7 +55,7 @@ Item.propTypes = {
methods: PropTypes.any,
item: PropTypes.any,
itemIndex: PropTypes.any
}
};

const ItemComponent = styled.span`
padding: 5px 10px;
Expand Down

0 comments on commit aa05354

Please sign in to comment.