Skip to content

Popover is misaligned on fractional pixels #46313

Open
@patorjk

Description

@patorjk

Steps to reproduce

Steps:

  1. Open this link to live example: https://stackblitz.com/edit/github-tt94w8is?file=src%2FApp.tsx
    • Type in the textfield to see the popover, press "Esc" to hide it (also hides on blur).
  2. You'll need to zoom to a different level to see the misalignment problem - usually 150% or 125%. See the screenshot below for what I'm referring to. The popover becomes misaligned when fractions of a pixel are at play, usually this occurs when zoomed in.
  3. Type in the textfield and the popover will pop-up and be misaligned by a fraction of a pixel (side note: if you zoom with the popover it becomes misaligned, but this is not what I'm referring to).
  4. It seems that MUI rounds the left and top positions (https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Popover/Popover.js#L279), thus fractional pixels sometimes cause misalignment. This leads to a "broken" effect when popovers are connecting to other UI elements.
    Example of the problem:
    Image

The popover is misaligned by a fraction of a pixel. I believe this is due to the rounding that occurs in the popover element.

Current behavior

Currently MUI round the top and left positions, thus the popover snaps to the pixel grid rather than being directly aligned with the element its supposed to align with.

Expected behavior

The popover should align with the element its suppose to align with, even if fractional pixels are at play.

Context

I'm creating a search suggestion component.

Your environment

npx @mui/envinfo
  System:
    OS: Linux 4.18 Red Hat Enterprise Linux 8.10 (Ootpa)
  Binaries:
    Node: 20.19.0 - ~/.nvm/versions/node/v20.19.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.19.0/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
  npmPackages:
    @emotion/react: ^11.11.4 => 11.11.4 
    @emotion/styled: ^11.11.5 => 11.11.5 
    @mui/base: ^5.0.0-beta.48 => 5.0.0-beta.61 
    @mui/core-downloads-tracker:  6.1.6 
    @mui/icons-material: 6.1.6 => 6.1.6 
    @mui/lab: 6.0.0-beta.14 => 6.0.0-beta.14 
    @mui/material: 6.1.6 => 6.1.6 
    @mui/private-theming: ^5.15.14 => 5.15.14 
    @mui/styled-engine:  6.1.6 
    @mui/system: 6.1.6 => 6.1.6 
    @mui/types:  7.2.19 
    @mui/utils: 6.1.6 => 6.1.6 
    @mui/x-data-grid: ^7.14.0 => 7.16.0 
    @mui/x-date-pickers: ^7.22.1 => 7.22.1 
    @mui/x-internals:  7.15.0 
    @mui/x-tree-view:  7.15.0 
    @types/react:  18.3.3 
    react: ^18.1.0 => 18.2.0 
    react-dom: ^18.1.0 => 18.2.0 
    typescript:  4.9.5 

I'm using Chrome (Version 126.0.6478.182 (Official Build) (64-bit))

Search keywords: fractional, zoom

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions