From c4383e61a10179356e0690005e5467a2b2727e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Fri, 13 Jun 2014 16:22:38 -0400 Subject: [PATCH] Selectmenu: Close on scroll Fixes #10082 --- tests/unit/selectmenu/selectmenu_core.js | 13 +++++++++++++ ui/selectmenu.js | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/unit/selectmenu/selectmenu_core.js b/tests/unit/selectmenu/selectmenu_core.js index e9312d12fc1..51d4d26c6ef 100644 --- a/tests/unit/selectmenu/selectmenu_core.js +++ b/tests/unit/selectmenu/selectmenu_core.js @@ -271,4 +271,17 @@ $.each([ }); }); +test( "close on scroll", function() { + expect( 2 ); + + var element = $( "#speed" ).selectmenu(), + menu = element.selectmenu( "menuWidget" ); + + element.selectmenu( "open" ); + ok( menu.is( ":visible" ), "Menu is visible on open" ); + + element.parent().trigger( "scroll" ); + ok( menu.is( ":hidden" ), "Menu is hidden after scroll" ); +}); + })( jQuery ); diff --git a/ui/selectmenu.js b/ui/selectmenu.js index 2107285fe36..60a80760352 100644 --- a/ui/selectmenu.js +++ b/ui/selectmenu.js @@ -235,8 +235,15 @@ return $.widget( "ui.selectmenu", { this._resizeMenu(); this._position(); + // Close the menu if the user clicks anywhere outside of the select this._on( this.document, this._documentClick ); + // Close the menu if the user scrolls any ancestor + this.scrollElements = this.widget().parents().add( document ); + this._on( this.scrollElements, { + scroll: "close" + }); + this._trigger( "open", event ); }, @@ -252,7 +259,7 @@ return $.widget( "ui.selectmenu", { this.isOpen = false; this._toggleAttr(); - this._off( this.document ); + this._off( this.scrollElements ); this._trigger( "close", event ); },