Skip to content

Commit

Permalink
1294 Updated componentDidUpdate in Select to now set the scroll top t…
Browse files Browse the repository at this point in the history
…o the previous option if it is disabled, it will show the disabled option even if it isn't focused.

JedWatson#1294
  • Loading branch information
enf0rc3 committed Jan 17, 2017
1 parent ef3a468 commit eefc671
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,26 @@ const Select = React.createClass({
componentDidUpdate (prevProps, prevState) {
// focus to the selected option
if (this.menu && this.focused && this.state.isOpen && !this.hasScrolledToOption) {
let focusedOptionNode = ReactDOM.findDOMNode(this.focused);
let menuNode = ReactDOM.findDOMNode(this.menu);
menuNode.scrollTop = focusedOptionNode.offsetTop;
// Set Scroll Location of the Drop down.
// If focus is null or set to the first option
if(!this.focused || this.focused.props.optionIndex == 0){
// Set the menu scroll to the top.
menuNode.scrollTop = 0;
}else{
// Check the previous setting incase its 'disabled'
let previousOptionToFocused = this.props.options[this.focused.props.optionIndex - 1]
if (previousOptionToFocused && previousOptionToFocused.disabled){
// If the previous sibling is disabled, make the disabled option shown.
// on the drop down above the focused option.
let focusedNodesPreviousSibling = ReactDOM.findDOMNode(this.focused).previousSibling;
menuNode.scrollTop = focusedNodesPreviousSibling.offsetTop;
}else{
// Set the Top option on the drop down to be the focused option.
let focusedOptionNode = ReactDOM.findDOMNode(this.focused);
menuNode.scrollTop = focusedOptionNode.offsetTop;
}
}
this.hasScrolledToOption = true;
} else if (!this.state.isOpen) {
this.hasScrolledToOption = false;
Expand Down

0 comments on commit eefc671

Please sign in to comment.