Opened 2 years ago
Closed 2 years ago
#10142 closed feature (fixed)
Selectmenu: Can't style selected item
| Reported by: | spjonez | Owned by: | fnagel |
|---|---|---|---|
| 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 2 years ago by tj.vantoll
- Owner set to spjonez
- Status changed from new to pending
comment:2 Changed 2 years ago by spjonez
- Status changed from pending to new
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.
comment:3 Changed 2 years ago by scottgonzalez
- Status changed from new to open
- Type changed from bug to feature
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 follow-up: ↓ 5 Changed 2 years ago by 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.
comment:5 in reply to: ↑ 4 Changed 2 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 2 years ago by tj.vantoll
#10189 is a duplicate of this ticket.
comment:7 Changed 2 years ago by tj.vantoll
- Summary changed from Can't style selected item in selectmenu to Selectmenu: 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 2 years ago by fnagel
- Owner spjonez deleted
- Status changed from open to assigned
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 2 years ago by scottgonzalez
- Milestone changed from none to 1.12.0
comment:10 Changed 2 years ago by scottgonzalez
- Owner set to fnagel
comment:11 Changed 2 years ago by Felix Nagel
- Resolution set to fixed
- Status changed from assigned to closed
Selectmenu: Introduce _renderButtonItem() method
Fixes #10142 Closes gh-1299
Changeset: fb4124b7af4e87712eca9893f7aefb5fee7905de
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/?