Skip to content

Controlgroup: Correctly handle non-empty child class key #1713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

gabrielschulhof
Copy link

No description provided.

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @arschmitz and @jzaefferer to be potential reviewers


} );

} );
Copy link
Member

Choose a reason for hiding this comment

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

This should not be its own file

@arschmitz
Copy link
Member

I don't see where you have addressed the vast majority of my comments and I see more changes with absolutely no explanation.

@arschmitz
Copy link
Member

Also failing jshint

@gabrielschulhof
Copy link
Author

@arschmitz good that you told me to add the HTML into the markup! It exposed another problem: If you let the controlgroup instantiate the children, it always instantiates them with options, including classes options, but which are calculated without taking into account the default classes options stored in the prototype, because there is no instance on which to base those options. So, the prototype has to be the instance in that case, but the prototype cannot be gotten from the plugin. So, it has to be tacked onto the plugin in $.widget.bridge.

.controlgroup()
.controlgroup( "instance" );

assert.deepEqual(
Copy link
Member

Choose a reason for hiding this comment

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

Again why are you not just using hasClasses to ensure the element has the classes we want

Copy link
Author

@gabrielschulhof gabrielschulhof Jun 14, 2016

Choose a reason for hiding this comment

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

Because it's not the classes on the element that are wrong, but the value of the class key that's wrong.
.toggleClass() de-dupes when it applies classes, but the class key can look like "something-custom something-custom something-custom something-custom ui-corner-left".

Copy link
Author

Choose a reason for hiding this comment

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

So, this is about the JS side, not the resulting markup.

Copy link
Member

Choose a reason for hiding this comment

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

ok and why do we care if a user does that what does this break?

Copy link
Author

@gabrielschulhof gabrielschulhof Jun 14, 2016

Choose a reason for hiding this comment

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

The user doesn't do that. Controlgroup does that by the way it computes a value for the classes option.

Copy link
Author

@gabrielschulhof gabrielschulhof Jun 14, 2016

Choose a reason for hiding this comment

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

So, the user innocently sets $.ui.selectmenu.prototype.options.classes[ "ui-selectmenu-button-closed" ] to, say, "ui-shadow" and we proceed to mangle that value in every instance of a selectmenu that resides inside a controlgroup. Oh, and it's worse, because the length of the string increases with each refresh().

Copy link
Member

Choose a reason for hiding this comment

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

I still dont think we need to test for that when the bug only existed as part of a greater bug that would have also failed with just a hasClasses check.

Alternatively if you really think this is important for you to check make it a separate test and just use matches on instance.options.classes[ 'whatever-key' ] and check the length of the class you added it should never be more then 1.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, OK, I see what you're saying. I do believe that we should test both the class value with .hasClasses() and the class key value.

@gabrielschulhof
Copy link
Author

I'll add more comments.


// If the button is the child of a spinner ignore it
if ( widget === "button" && element.parent( ".ui-spinner" ).length ) {
return;
}
if ( instance ) {
options.classes = that._resolveClassesValues( options.classes, instance );
if ( defaultInstance ) {
Copy link
Member

@arschmitz arschmitz Jun 14, 2016

Choose a reason for hiding this comment

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

Instead of all this why not just

if ( !instance ) {
   element[ widget ]();
}

Copy link
Author

Choose a reason for hiding this comment

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

OK, instantiate with default options first, and then call options. I can do that.

@scottgonzalez
Copy link
Member

Please file an issue about whatever is being fixed.

@gabrielschulhof gabrielschulhof force-pushed the non-empty-class-key branch 4 times, most recently from d6180d5 to 2c9c6e0 Compare June 14, 2016 17:25
gabrielschulhof pushed a commit to gabrielschulhof/jquery-ui that referenced this pull request Jun 14, 2016
.selectmenu( "option", "classes" )[ "ui-selectmenu-button-closed" ]
.match( /something-custom/ ) || [] ).length, 1,
"Class 'something-custom' appears exactly once in the second widget's class key value" );
} );
Copy link
Member

Choose a reason for hiding this comment

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

can we shorten all the class and id's here and in the html kind of excessively long

Copy link
Author

Choose a reason for hiding this comment

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

Sure can :)

gabrielschulhof pushed a commit to gabrielschulhof/jquery-ui that referenced this pull request Jun 14, 2016
gabrielschulhof pushed a commit to gabrielschulhof/jquery-ui that referenced this pull request Jun 14, 2016
QUnit.module( "Controlgroup: Non-empty class key", {
setup: function() {
this.classKey = $.ui.selectmenu.prototype.options.classes[ "ui-selectmenu-button-closed" ];
$.ui.selectmenu.prototype.options.classes[ "ui-selectmenu-button-closed" ] =
Copy link
Member

Choose a reason for hiding this comment

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

why dont we just hard code a value here to simplify it really does not matter what we set here just that we set something non default

Copy link
Author

Choose a reason for hiding this comment

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

Done.

gabrielschulhof pushed a commit to gabrielschulhof/jquery-ui that referenced this pull request Jun 14, 2016
// We need to clone the default options for this type of widget to avoid
// polluting the variable options which has a wider scope than a single widget.
var instanceOptions = $.widget.extend( {}, options );

// If the button is the child of a spinner ignore it
if ( widget === "button" && element.parent( ".ui-spinner" ).length ) {
Copy link
Member

Choose a reason for hiding this comment

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

I know you're not touching this block of code, but since you're modifying a bunch of code around it, can you just add a comment here that says "TODO: Find a more generic solution"? This is something @arschmitz and I discussed before, but we don't have any ideas for how to implement it.

@gabrielschulhof
Copy link
Author

@scottgonzalez I have addressed your review comments.

@arschmitz
Copy link
Member

thank you I will merge this shortly

@arschmitz arschmitz closed this in 3a9a3c7 Jul 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants