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][material] Fix select menu moving on scroll when disableScrollLock is true #37773

Merged
merged 19 commits into from
Aug 24, 2023

Conversation

VishruthR
Copy link
Contributor

@VishruthR VishruthR commented Jul 1, 2023

Solves bug where if a user has a Select component with a MenuList that has disableScrollLock set to true, the MenuList will scroll with the screen.

Demo of bug: https://codesandbox.io/s/bitter-violet-wpfhc4?file=/src/App.js

Closes #37752

Recording 2023-07-02 at 10 26 12

@VishruthR VishruthR changed the title [Select][material] Fix select menu moving on scroll [Select][material] Fix select menu moving on scroll when disableScrollLock is false Jul 1, 2023
@VishruthR VishruthR changed the title [Select][material] Fix select menu moving on scroll when disableScrollLock is false [Select][material] Fix select menu moving on scroll when disableScrollLock is true Jul 1, 2023
@mui-bot
Copy link

mui-bot commented Jul 1, 2023

Netlify deploy preview

https://deploy-preview-37773--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 8adf73f

@zannager zannager added the component: select This is the name of the generic UI component, not the React module! label Jul 3, 2023
@zannager zannager requested a review from michaldudak July 3, 2023 13:00
@VishruthR
Copy link
Contributor Author

@michaldudak @gzrae Right now the ci/codesandbox build is failing and I'm not sure why. When I run yarn build:codesandbox locally it works fine. Do you have any idea what might be wrong?

@VishruthR
Copy link
Contributor Author

@michaldudak @gzrae Right now the ci/codesandbox build is failing and I'm not sure why. When I run yarn build:codesandbox locally it works fine. Do you have any idea what might be wrong?

Hi, just wanted to follow up on this question and see if you guys had any thoughts?

Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @VishruthR, thanks for working on this! 😊 And sorry for the late response.

I think the solution works 🚀 I added two comments to improve it, let me know what you think

packages/mui-material/src/Popover/Popover.js Outdated Show resolved Hide resolved
packages/mui-material/src/Popover/Popover.js Outdated Show resolved Hide resolved
@DiegoAndai DiegoAndai added the package: material-ui Specific to @mui/material label Jul 26, 2023
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 29, 2023
Signed-off-by: Vishruth Raj <42901020+VishruthR@users.noreply.github.com>
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 30, 2023
@@ -6,11 +6,10 @@ import Typography from '@mui/joy/Typography';
const customTheme = extendTheme({
typography: {
kbd: {
background:
'linear-gradient(to top, var(--joy-palette-background-level2), var(--joy-palette-background-surface))',
backgroundColor: 'var(--joy-palette-background-surface)',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I ran yarn docs:typescript:formatted this file changed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to a Joy UI default theme update: https://github.com/mui/material-ui/pull/36843/files#diff-300d121fc27c24b580132ae34564f8ac77dfb0aeaeaa3dcbcce03c3ff31b7011

Can you try merging the latest master to your branch and see if this change goes away?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git seems to think my branch is up to date with master so merging does nothing.

Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on the feedback 😊

A couple more polish comments 🙌🏼

packages/mui-material/src/Popover/Popover.js Outdated Show resolved Hide resolved
packages/mui-material/src/Popover/Popover.js Outdated Show resolved Hide resolved
...other
} = props;

const disableScrollLock = props.disableScrollLock ?? false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be added to the props destructure:

// ...
disableMarginThreshold = false,
disableScrollLock = false,
...other

We would have to explicitly add it to the Root props as it won't go inside the other props anymore, so on line 416:

  const { slotProps: rootSlotPropsProp, ...rootProps } = useSlotProps({
    elementType: RootSlot,
    externalSlotProps: slotProps?.root || {},
-   externalForwardedProps: other,
+   externalForwardedProps: {
+       disableScrollLock,
+       ...other
+   },
    additionalProps: {
      ref,
      slotProps: { backdrop: { invisible: true } },
      container,
      open,
    },
    ownerState,
    className: clsx(classes.root, className),
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like adding this line caused me to fail a unit test. I'm not too sure what this error is saying exactly so any guidance would be great!

  1) <Menu />
       MUI component API
         allows overriding the root slot with an element using the slots.root prop:
     Expected test not to call console.error() but instead received 1 calls.

If the warning is expected, test for it explicitly by using the toErrorDev() matcher.
Test location:
  /tmp/material-ui/packages/mui-material/src/Menu/Menu.test.js 

console.error message #1:
  Warning: React does not recognize the `disableScrollLock` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `disablescrolllock` instead. If you accidentally passed it from a parent component, remove it from the DOM element.
    at i
    at Popover (/tmp/material-ui/packages/mui-material/src/Popover/Popover.js:4389:71)
    at /tmp/material-ui/node_modules/@emotion/react/dist/emotion-element-48d2c2e4.cjs.dev.js:62:23
    at Menu (/tmp/material-ui/packages/mui-material/src/Menu/Menu.js:1761:70)
    at Wrapper (/tmp/material-ui/test/utils/createRenderer.tsx:403:7)

@@ -6,11 +6,10 @@ import Typography from '@mui/joy/Typography';
const customTheme = extendTheme({
typography: {
kbd: {
background:
'linear-gradient(to top, var(--joy-palette-background-level2), var(--joy-palette-background-surface))',
backgroundColor: 'var(--joy-palette-background-surface)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to a Joy UI default theme update: https://github.com/mui/material-ui/pull/36843/files#diff-300d121fc27c24b580132ae34564f8ac77dfb0aeaeaa3dcbcce03c3ff31b7011

Can you try merging the latest master to your branch and see if this change goes away?

@DiegoAndai
Copy link
Member

Here's the original repro codesandbox: https://codesandbox.io/s/bitter-violet-wpfhc4?file=/src/App.js:0-704

Here's the codesandbox showcasing the new functionality by using disableLockScroll and disableMarginThreshold: https://codesandbox.io/s/scrollable-select-vnppl4

@michaldudak may I ask a review from you here?

const positioningStyle = getElementStyleOfOpenPopover(mockedAnchor);

expect(positioningStyle.top).to.equal(`${marginThreshold}px`);
expect(positioningStyle.left).to.equal(`${marginThreshold}px`);
expect(positioningStyle.transformOrigin).to.match(/0px 1px( 0px)?/);
expect(positioningStyle.transformOrigin).to.match(/0px -1px( 0ms)?/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 0ms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DiegoAndai DiegoAndai self-assigned this Aug 21, 2023
Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bnussman-akamai
Copy link

Thank you for fixing this! I'm seeing that on MacOS, the bouncy-scroll does not play well with this. Is there anything that can be done about this?

Screen.Recording.2023-08-30.at.7.20.09.PM.mov

@michaldudak
Copy link
Member

@bnussman-akamai, could you please open a new issue so we can track this problem?

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! package: material-ui Specific to @mui/material
Projects
Status: Recently completed
Development

Successfully merging this pull request may close these issues.

TextField component's with select option and disableScrollLock menu stays fixed when scrolling
6 participants