Skip to content

Commit

Permalink
[AutoComplete] Prevent menu from closing when clicking scrollbar in IE11
Browse files Browse the repository at this point in the history
Fixes mui#5178 by wrapping the menu in a `div` which uses `onMouseEnter`
and `onMouseLeave` to determine if the scrollbar was clicked.
  • Loading branch information
camagu committed May 18, 2017
1 parent 3e22d8e commit 5529cba
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/AutoComplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ class AutoComplete extends Component {
}
};

handleMouseEnter = () => {
this.setState({isMouseOverMenu: true});
};

handleMouseLeave = () => {
this.setState({isMouseOverMenu: false});
};

handleMouseDown = (event) => {
// Keep the TextField focused
event.preventDefault();
Expand Down Expand Up @@ -356,7 +364,7 @@ class AutoComplete extends Component {
};

handleBlur = (event) => {
if (this.state.focusTextField && this.timerTouchTapCloseId === null) {
if (this.state.focusTextField && !this.state.isMouseOverMenu && this.timerTouchTapCloseId === null) {
this.timerBlurClose = setTimeout(() => {
this.close();
}, 0);
Expand All @@ -368,6 +376,8 @@ class AutoComplete extends Component {
};

handleFocus = (event) => {
clearTimeout(this.timerBlurClose);

if (!this.state.open && this.props.openOnFocus) {
this.setState({
open: true,
Expand Down Expand Up @@ -500,20 +510,26 @@ class AutoComplete extends Component {
this.requestsList = requestsList;

const menu = open && requestsList.length > 0 && (
<Menu
ref="menu"
autoWidth={false}
disableAutoFocus={focusTextField}
onEscKeyDown={this.handleEscKeyDown}
initiallyKeyboardFocused={true}
onItemTouchTap={this.handleItemTouchTap}
onMouseDown={this.handleMouseDown}
style={Object.assign(styles.menu, menuStyle)}
listStyle={Object.assign(styles.list, listStyle)}
{...menuProps}
<div
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
onBlur={this.handleBlur}
>
{requestsList.map((i) => i.value)}
</Menu>
<Menu
ref="menu"
autoWidth={false}
disableAutoFocus={focusTextField}
onEscKeyDown={this.handleEscKeyDown}
initiallyKeyboardFocused={true}
onItemTouchTap={this.handleItemTouchTap}
onMouseDown={this.handleMouseDown}
style={Object.assign(styles.menu, menuStyle)}
listStyle={Object.assign(styles.list, listStyle)}
{...menuProps}
>
{requestsList.map((i) => i.value)}
</Menu>
</div>
);

return (
Expand Down

0 comments on commit 5529cba

Please sign in to comment.