aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2023-05-10 10:55:01 +0200
committerGitHub <noreply@github.com>2023-05-10 10:55:01 +0200
commit020828e7ffd5e7830d979b4c5cf8412f04223973 (patch)
tree323d777eaabdabbdce36008926817275df7d9a8b /tests
parentbeeb410ccbe1c4108ee93bdbdc05e003f115baf6 (diff)
downloadjquery-ui-020828e7ffd5e7830d979b4c5cf8412f04223973.tar.gz
jquery-ui-020828e7ffd5e7830d979b4c5cf8412f04223973.zip
Selectmenu: Fix selecting options following hidden ones
Change a2b25ef6caae3e1a272214839b815a6387618124 made options with the `hidden` attribute skipped when rendering. However, that makes indexes misaligned with native options as hidden ones maintain their index values. Instead, don't skip hidden options but add the `hidden` attribute to the respective jQuery UI elements as well. Fixes gh-2082 Closes gh-2144 Ref a2b25ef6caae3e1a272214839b815a6387618124
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/selectmenu/core.js65
1 files changed, 62 insertions, 3 deletions
diff --git a/tests/unit/selectmenu/core.js b/tests/unit/selectmenu/core.js
index f32cec9b9..f8daf4db0 100644
--- a/tests/unit/selectmenu/core.js
+++ b/tests/unit/selectmenu/core.js
@@ -394,16 +394,75 @@ QUnit.test( "Options with hidden attribute should not be rendered", function( as
setTimeout( function() {
button.trigger( "click" );
options = menu.children()
- .map( function() {
- return $( this ).text();
+ .get()
+ .filter( function( item ) {
+ return $( item ).is( ":visible" );
} )
- .get();
+ .map( function( item ) {
+ return $( item ).text();
+ } );
assert.deepEqual( options, [ "Slower", "Medium", "Fast", "Faster" ], "correct elements" );
ready();
} );
} );
+QUnit.test( "Options with hidden attribute should not break the widget (gh-2082)",
+ function( assert ) {
+ var ready = assert.async();
+ assert.expect( 1 );
+
+ var button;
+ var element = $( "#speed" );
+
+ element.find( "option" ).slice( 0, 2 ).prop( "hidden", true );
+ element.val( "Faster" );
+ element.selectmenu();
+
+ button = element.selectmenu( "widget" );
+ button.simulate( "focus" );
+ setTimeout( function() {
+ try {
+ button.trigger( "click" );
+ assert.strictEqual( button.text(), "Faster", "Selected value is correct" );
+ } catch ( e ) {
+ assert.ok( false, "Clicking on the select box crashed" );
+ }
+
+ ready();
+ } );
+} );
+
+QUnit.test( "Optgroups with hidden attribute should not break the widget (gh-2082)",
+ function( assert ) {
+ var ready = assert.async();
+ assert.expect( 1 );
+
+ var button;
+ var element = $( "#files" );
+
+ element.find( "optgroup" ).first().prop( "hidden", true );
+ element
+ .find( "optgroup" ).eq( 1 )
+ .find( "option" ).first()
+ .prop( "hidden", true );
+ element.val( "someotherfile" );
+ element.selectmenu();
+
+ button = element.selectmenu( "widget" );
+ button.simulate( "focus" );
+ setTimeout( function() {
+ try {
+ button.trigger( "click" );
+ assert.strictEqual( button.text(), "Some other file", "Selected option is correct" );
+ } catch ( e ) {
+ assert.ok( false, "Clicking on the select box crashed" );
+ }
+
+ ready();
+ } );
+} );
+
QUnit.test( "extra listeners created after selection (trac-15078, trac-15152)", function( assert ) {
assert.expect( 3 );