SelectOneMenu: add support to use icons
See original GitHub issueDescription At this time we are allowed to use icons at SelectOneMenu, but only when the options are expanded. We can see an example in the showcase: https://www.primefaces.org/showcase/ui/input/oneMenu.xhtml. My suggestion is to improve the component to allow us to add only an icon like InputGroup component is.
Additional context
Below a screenshot with my proposal. On the right side is the current behavior: the only text is allowed. In the left side the component with icon only support:
Example XHTML
<p:selectOneMenu value="#{selectOneMenuView.theme}">
<f:selectItems value="#{selectOneMenuView.themes}" var="theme" itemLabel="#{theme.displayName}" itemValue="#{theme}" />
<p:column>
<f:facet name="some-facet-name">
<i class="pi pi-check"></i> <!-- this can be an icon, or another HTML component like image, etc -->
</facet>
<h:outputText value=" #{theme.name}" />
</p:column>
</p:selectOneMenu>
With some guidance, helping me to understand the better design for this change, I can try a PR if you like the idea.
Thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
PrimeFaces SelectOneMenu with icons (custom f:selectItems)
As you can see, I am trying to render the icon using a p:button . Do I understand it correctly that I need...
Read more >Adding icons to SelectOneMenu with columns
I am trying to implement the SelectOneMenu advanced property, to add an icon in my optinons.
Read more >RichFaces f:selectItems with flag icons - JBoss.org
I'm developing a JSF web appication using RichFaces library. Application supports different locales, and user is able to change them by ...
Read more >Combobox (<b:selectOneMenu>) - BootsFaces Showcase
<b:selectOneMenu> makes the Bootstrap style of displaying comboboxes ... To do so, you just need to use the facets prepend and append where...
Read more >PrimeFaces SelectOneMenu with FontAwesome icons ...
PrimeFaces SelectOneMenu with FontAwesome icons (custom f:selectItems). jsfprimefaces ... P.S.: Using PrimeFaces 5.3, JSF 2.2 and Mojarra on WildFly 9.0.2 ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @melloware. Thank you for you time on this.
The InputGroup is not possible here because it is static. What I need is like an InputGroup, but dynamic. This is the reason because I choose SelectOneMenu.
In my case, I have a contact form, and the user needs to set their contact type (if e-mail, cellphone, home phone or work phone). At this time I have this component:
But when the user selects an option, the SelectOneMenu looks like this (without the related icon):
What I need in that case is to have an “e-mail” icon instead of only the e-mail text. The current SelectOneMenu allows me to have an icon + text when the SelectOneMenu is expanded.
Do let me know if I was able to explain my case for you.
Thank you
I also have been missing icon support for selectOneMenu in the past. As a workaround I use a menuButton instead, but results are visually not fully convincing as seen in below example (Unable to place an icon in the displayed text, unable to give icons a color). The icon on the left side has been placed there as a seperate entity. I skipped selectOneMenu completely mostly for aesthetic reasons.
To get back to the original proposal: I am not convinced as well with the proposed solution. I think the main problem is here, that the column-based solution for icons in the showcase is more of a hack than a real solution to start with.
Most other components have a clear interface for handling icons, but selectOneMenu does not. The culprit lies in the use of f:selectItem for the menu model, which does not have a way to specify an icon alongside the label and value.
Two possible solutions come to mind here:
Additionally other common icon related attributes (iconPos, iconOnly etc.) should be added as well.
I personally would go in favor of the second solution.
What do you think?