Skip to content

Commit

Permalink
Selectmenu: Don't render options with the hidden attribute
Browse files Browse the repository at this point in the history
Fixes #15098
  • Loading branch information
scottgonzalez committed Nov 16, 2016
1 parent 9a4c057 commit a2b25ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/unit/selectmenu/core.js
Expand Up @@ -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();
} );
} );

} );
4 changes: 4 additions & 0 deletions ui/widgets/selectmenu.js
Expand Up @@ -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;
Expand Down

2 comments on commit a2b25ef

@thomasbao12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried cherrypicking this onto v1.12.1, but it actually causes a regression. If I select the last visible item, the select button stops working. There's a mismatch between indices, resulting in trying to grab index from an undefined element.

@fnagel
Copy link
Member

@fnagel fnagel commented on a2b25ef Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2144

Please sign in to comment.