Opened 3 years ago

Closed 3 years ago

#10142 closed feature (fixed)

Selectmenu: Can't style selected item

Reported by: spjonez Owned by: Felix Nagel
Priority: minor Milestone: 1.12.0
Component: ui.selectmenu Version: 1.11.0
Keywords: Cc:
Blocked by: Blocking:

Description

Using _renderItem you can manipulate the markup for items in the flyout dropdown, but those styles do not apply to the selected item when the list is collapsed. If you want to change the color of each item using a CSS class you can add a wrapper in _renderItem. However once you select an item the class is lost and the default style is shown.

This issue was not present in the original selectmenu plugin.

Change History (11)

comment:1 Changed 3 years ago by tj.vantoll

Owner: set to spjonez
Status: newpending

Hi spjonez,

Thanks for taking the time to contribute to jQuery UI. Just so that I understand your use case, do you want the styles applied to the item in the dropdown to be reflected after that option is selected? For instance the colors to be preserved in this example: http://jsfiddle.net/tj_vantoll/B9SCN/?

comment:2 Changed 3 years ago by spjonez

Status: pendingnew

Yes exactly. In the original plugin the modified markup of list items applied to the selected item as well. So in your example, after init 'red' should be red, and as you change items the colour should carry through. It seems custom markup is stripped or not used for the default/selected option. Ideally the same custom markup would be used in both places.

Last edited 3 years ago by spjonez (previous) (diff)

comment:3 Changed 3 years ago by Scott González

Status: newopen
Type: bugfeature

I could see the items being rendered very differently in the dropdown and the button form, so we'll need to have a separate method for that rendering, but it should certainly be easy to use the same rendering for both.

comment:4 Changed 3 years ago by Felix Nagel

The button (the selected item) is just a generated span, not a list item.

I think what you want to achieve can be easily done by using callback events, see: http://jsfiddle.net/B9SCN/3/

Providing a private method which could be overridden should be no problem but using the same mechanism for list items and the form button seems not that useful to me.

comment:5 in reply to:  4 Changed 3 years ago by tj.vantoll

Replying to fnagel:

The button (the selected item) is just a generated span, not a list item.

I think what you want to achieve can be easily done by using callback events, see: http://jsfiddle.net/B9SCN/3/

Providing a private method which could be overridden should be no problem but using the same mechanism for list items and the form button seems not that useful to me.

IMO the logic to render the item could be complex and something you wouldn't want to duplicate. I like a new extension method for this, maybe _renderSelectedItem()?

comment:6 Changed 3 years ago by tj.vantoll

#10189 is a duplicate of this ticket.

comment:7 Changed 3 years ago by tj.vantoll

Summary: Can't style selected item in selectmenuSelectmenu: Can't style selected item

This should cover the use case presented in #10189. If you customize the text shown in the "options", that text should be used in the button, or you should have a documented way to accomplish that. For example http://jsfiddle.net/tj_vantoll/9Njge/.

comment:8 Changed 3 years ago by Felix Nagel

Owner: spjonez deleted
Status: openassigned

I've discussed this with Scott and we agreed on implementing a _renderButton method. See https://github.com/jquery/jquery-ui/pull/1297

comment:9 Changed 3 years ago by Scott González

Milestone: none1.12.0

comment:10 Changed 3 years ago by Scott González

Owner: set to Felix Nagel

comment:11 Changed 3 years ago by Felix Nagel

Resolution: fixed
Status: assignedclosed

Selectmenu: Introduce _renderButtonItem() method

Fixes #10142 Closes gh-1299

Changeset: fb4124b7af4e87712eca9893f7aefb5fee7905de

Note: See TracTickets for help on using tickets.