How can I get p:selectOneMenu to calculate its width correctly inside dialogs?

Michael Calvin picture Michael Calvin · Sep 6, 2012 · Viewed 11.2k times · Source

When I embed a p:selectOneMenu in a p:dialog, its initial width is too small in Primefaces 3.4. The width of these widgets was perfectly fine in Primefaces 3.2. Do I need to do a hack to get around this?

The problem manifests in Chrome. The following example code demonstrates the problem:

<p:selectOneMenu value="A" onchange="testDialog.show()">
  <f:selectItem itemLabel="Default item" itemValue="A" />
  <f:selectItem itemLabel="Click here to show the dialog" itemValue="B" />
</p:selectOneMenu>
<p:dialog header="Test dialog" widgetVar="testDialog">
  <p:selectOneMenu value="A">
    <f:selectItem itemLabel="This one here in the dialog" itemValue="A" />
    <f:selectItem itemLabel="doesn't calculate" itemValue="B" />
    <f:selectItem itemLabel="its width" itemValue="C" />
    <f:selectItem itemLabel="correctly" itemValue="D" />
  </p:selectOneMenu>
</p:dialog>

Answer

Jaron picture Jaron · Oct 15, 2012

I was able to reproduce your problem; it's like the dropdown button is blissfully ignorant of the fact it's covering up the textbox. On my setup I was able to get the selectOneMenus to appear properly with this CSS fix:

<style type="text/css">
    .ui-selectonemenu label.ui-selectonemenu-label {
        padding-right: 28px;
        text-align: left;
    }
</style>

Edit: Oh whoops, I see this solution is very similar to akoskm's comment. But I tried that at the time and text-align: right wasn't working for me; only text-align: left was leaving the characters uncovered.