Skip to content

Selectmenu: Introduce _renderButton method #1297

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
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions ui/selectmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ return $.widget( "ui.selectmenu", {
},

_drawButton: function() {
var that = this,
tabindex = this.element.attr( "tabindex" );
var that = this;

// Associate existing label with the new button
this.label = $( "label[for='" + this.ids.element + "']" ).attr( "for", this.ids.button );
Expand All @@ -83,28 +82,7 @@ return $.widget( "ui.selectmenu", {
this.element.hide();

// Create button
this.button = $( "<span>", {
"class": "ui-selectmenu-button ui-widget ui-state-default ui-corner-all",
tabindex: tabindex || this.options.disabled ? -1 : 0,
id: this.ids.button,
role: "combobox",
"aria-expanded": "false",
"aria-autocomplete": "list",
"aria-owns": this.ids.menu,
"aria-haspopup": "true"
})
.insertAfter( this.element );

$( "<span>", {
"class": "ui-icon " + this.options.icons.button
})
.prependTo( this.button );

this.buttonText = $( "<span>", {
"class": "ui-selectmenu-text"
})
.appendTo( this.button );

this._renderButton();
this._setText( this.buttonText, this.element.find( "option:selected" ).text() );
this._resizeButton();

Expand Down Expand Up @@ -267,6 +245,30 @@ return $.widget( "ui.selectmenu", {
return this.menu;
},

_renderButton: function() {
this.button = $( "<span>", {
"class": "ui-selectmenu-button ui-widget ui-state-default ui-corner-all",
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't do any assigning. It should just return an element.

tabindex: this.element.attr( "tabindex" ) || this.options.disabled ? -1 : 0,
id: this.ids.button,
role: "combobox",
"aria-expanded": "false",
"aria-autocomplete": "list",
"aria-owns": this.ids.menu,
"aria-haspopup": "true"
Copy link
Member

Choose a reason for hiding this comment

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

None of this can be in here. These are all required functionality.

})
.insertAfter( this.element );
Copy link
Member

Choose a reason for hiding this comment

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

Insertion in the DOM in not part of rendering.


$( "<span>", {
"class": "ui-icon " + this.options.icons.button
})
Copy link
Member

Choose a reason for hiding this comment

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

I'm not thrilled about the fact that an extension point needs to concern itself with other built-in options, but I don't see any way around this.

.prependTo( this.button );

this.buttonText = $( "<span>", {
Copy link
Member

Choose a reason for hiding this comment

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

We cannot rely on this property existing once it goes into an extension point.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's needed to change the button text. Any idea how to work around?

"class": "ui-selectmenu-text"
})
.appendTo( this.button );
},

_renderMenu: function( ul, items ) {
var that = this,
currentOptgroup = "";
Expand Down