Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select menu width not taking border into account #41142

Closed
aldrichdev opened this issue Feb 17, 2024 · 3 comments
Closed

Select menu width not taking border into account #41142

aldrichdev opened this issue Feb 17, 2024 · 3 comments
Assignees
Labels
component: select This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow

Comments

@aldrichdev
Copy link

aldrichdev commented Feb 17, 2024

Steps to reproduce

Link to live example: https://stackblitz.com/edit/react-4lhmay?file=Demo.tsx

Steps:

  1. Observe the MuiFormControl-root width.
  2. Open the dropdown. Observe that the menu item widths are 4px less.
  3. The menu is not taking the 4px border (2px on left, 2px on right) of the select into account when calculating its width.

I am not sure why the menu appears slightly to the right under the dropdown, but I would ignore this, it is not happening in my project.

Current behavior

The width of the select menu is not calculated correctly because it does not include the select's borders in the calculation.

Expected behavior

The menu width should match the select width even if it has borders.

Context

I'm trying to get the dropdown menu to appear as the same width as the select without explicitly telling the menu to be 328px as well, and that solution isn't really viable for mobile since we want the select to be 100% of the width of the viewport.

Your environment

npx @mui/envinfo
  System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
    Edge: Chromium (121.0.2277.112)
  npmPackages:
    @emotion/react: ^11.11.1 => 11.11.1
    @emotion/styled: ^11.11.0 => 11.11.0
    @mui/core-downloads-tracker:  5.14.3
    @mui/icons-material: ^5.15.0 => 5.15.0
    @mui/material: ^5.14.3 => 5.14.3
    @mui/styled-engine:  5.13.2
    @mui/system: ^5.13.5 => 5.14.3
    @mui/types: ^7.2.4 => 7.2.4
    @mui/utils:  5.14.3
    @types/react: ^18.0.0 => 18.2.7
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    typescript: ^4.4.2 => 4.9.5

Search keywords: select menu width

@aldrichdev aldrichdev added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 17, 2024
@zannager zannager added the component: select This is the name of the generic UI component, not the React module! label Feb 18, 2024
@mj12albert
Copy link
Member

@aldrichdev This doesn't seem to be an issue with Material UI – since you are customizing the theme, you could probably offset the extra 4px by adding it back to the select menu (maybe with calc()or place the border on the FormControl instead of the input

@mj12albert mj12albert added support: Stack Overflow Please ask the community on Stack Overflow and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 20, 2024
Copy link

👋 Thanks for using MUI Core!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support, please check out https://mui.com/getting-started/support/. Thanks!

If you have a question on Stack Overflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2024
@aldrichdev
Copy link
Author

aldrichdev commented Feb 20, 2024

@aldrichdev This doesn't seem to be an issue with Material UI – since you are customizing the theme, you could probably offset the extra 4px by adding it back to the select menu (maybe with calc()or place the border on the FormControl instead of the input

Hi @mj12albert, thank you for your response. I tried setting width: calc(100% + 4px) on .MuiPaper-root, and this makes it full width of its container, or ~1600px on my screen instead of the expected 328px. I also tried placing the border on the FormControl instead of the input, but the menu still incorrectly calculates its width to be 324px wide.

Edit: I re-read the bot's message, and I see I shouldn't be putting support requests here. I've moved this to StackOverflow: https://stackoverflow.com/questions/78030607/mui-select-menu-width-not-taking-border-into-account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

3 participants