Opened 9 years ago
Closed 8 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 9 years ago by
Owner: | set to spjonez |
---|---|
Status: | new → pending |
comment:2 Changed 9 years ago by
Status: | pending → 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 9 years ago by
Status: | new → open |
---|---|
Type: | bug → 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 9 years ago by
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 Changed 9 years ago by
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:7 Changed 9 years ago by
Summary: | Can't style selected item in selectmenu → 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 9 years ago by
Owner: | spjonez deleted |
---|---|
Status: | open → 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 9 years ago by
Milestone: | none → 1.12.0 |
---|
comment:10 Changed 9 years ago by
Owner: | set to Felix Nagel |
---|
comment:11 Changed 8 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → 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/?