question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SelectOneMenu: computed inline style of width is 2px too much

See original GitHub issue

Describe the bug

The p:selectOneMenu computes inline styles for the class .ui-input-overlay:

<div class="ui-selectonemenu-panel ui-widget ui-widget-content ui-corner-all ui-helper-hidden ui-shadow ui-input-overlay ui-connected-overlay-exit-done" style="display: none; width: 815px; left: 447px; top: 123.1px; transform-origin: center top 0px;">..</div>

The width (in this case: 815px) is always 2 px too much. Please correct the calculation by substracting exactly 2px while calculating the inline style.

Reproducer

  1. Use any p:selectOneMenu
  2. Add the following css class to make the difference of 2px more visible:
body .ui-selectonemenu-panel {
  box-shadow: none;
  border-radius: 0;
  border: 1px solid blue;
}
  1. Then you see somehing like this:

2px-too-much

  1. Look at the inline styles of ui-selectonemenu-panel computed by PF and edit its width by substracting 2px. Then the width will be correctly aligned to its upper input-field and looks like this:

2px-less

Expected behavior

Correct inline width calculation of p:selectOneMenu. As the user cannot correct this issue by css (because its a calculated inline style of PF), it would be good if PF calculates its inline width correctly by substracting 2px within its calculation.

PrimeFaces edition

Community

PrimeFaces version

12

Theme

No response

JSF implementation

Mojarra

JSF version

2.3

Java version

17

Browser(s)

Firefox 107

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, Dec 14, 2022

Here is a MonkeyPatch just add this to your code and you should be able to tweak it however your want. That is the power of PrimeFaces!

if (PrimeFaces.widget.SelectOneMenu) {
    PrimeFaces.widget.SelectOneMenu.prototype.alignPanelWidth = function() {
        //align panel and container
        if (!this.panelWidthAdjusted) {
            var jqWidth = this.jq.outerWidth();
            if (this.panel.outerWidth() < jqWidth) {
                this.panel.width(jqWidth);
            } else {
                this.panel.width(this.panel.width());
            }

            this.panelWidthAdjusted = true;
        }
    };
}
0reactions
mellowarecommented, Dec 14, 2022

Yes, it’s a hack because the problem why 2px must be substracted is currently unknown…

That is the mystery! Something the way jQuery computes the width.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · primefaces/primefaces - GitHub
SelectOneMenu: computed inline style of width is 2px too much workaround A workaround has been provided. #9502 opened 7 hours ago by nimo23....
Read more >
html - inline css style width not able to override computed css ...
I'm seeing a strange behaviour which i'm not able to figure out. The webpage that i'm working on has a lot of css...
Read more >
inline-size - CSS: Cascading Style Sheets - MDN Web Docs
The inline-size CSS property defines the horizontal or vertical size of an element's block, depending on its writing mode.
Read more >
Inline Styling with React - Pluralsight
To use inline styles in React, use the style attribute, which accepts ... 4 height: 100, 5 width: 400, 6 boxShadow: "0 0...
Read more >
SelectOneMenu Width Too Small - Prime Community Forum
The width does not seem to be calculated correctly with the p:selectOneMenu. The down-chevron icon covers the last letter of the item.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found