From a2b25ef6caae3e1a272214839b815a6387618124 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 16 Nov 2016 12:52:15 -0500 Subject: [PATCH] Selectmenu: Don't render options with the `hidden` attribute Fixes #15098 --- tests/unit/selectmenu/core.js | 26 ++++++++++++++++++++++++++ ui/widgets/selectmenu.js | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/tests/unit/selectmenu/core.js b/tests/unit/selectmenu/core.js index a5bc68e0f..cef6dc5bf 100644 --- a/tests/unit/selectmenu/core.js +++ b/tests/unit/selectmenu/core.js @@ -376,4 +376,30 @@ QUnit.test( "Number pad input should change value", function( assert ) { } ); } ); +QUnit.test( "Options with hidden attribute should not be rendered", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); + + var button, menu, options, + element = $( "#speed" ); + + element.find( "option" ).eq( 1 ).prop( "hidden", true ); + element.selectmenu(); + button = element.selectmenu( "widget" ); + menu = element.selectmenu( "menuWidget" ); + + button.simulate( "focus" ); + setTimeout( function() { + button.trigger( "click" ); + options = menu.children() + .map( function() { + return $( this ).text(); + } ) + .get(); + assert.deepEqual( options, [ "Slower", "Medium", "Fast", "Faster" ], "correct elements" ); + + ready(); + } ); +} ); + } ); diff --git a/ui/widgets/selectmenu.js b/ui/widgets/selectmenu.js index 900a245f7..52139f73e 100644 --- a/ui/widgets/selectmenu.js +++ b/ui/widgets/selectmenu.js @@ -656,6 +656,10 @@ return $.widget( "ui.selectmenu", [ $.ui.formResetMixin, { var that = this, data = []; options.each( function( index, item ) { + if ( item.hidden ) { + return; + } + data.push( that._parseOption( $( item ), index ) ); } ); this.items = data; -- 2.39.5