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

[pickers] Datepicker flickers with custom textfield component #9525

Closed
2 tasks done
vishal-kadmos opened this issue Jun 30, 2023 · 4 comments
Closed
2 tasks done

[pickers] Datepicker flickers with custom textfield component #9525

vishal-kadmos opened this issue Jun 30, 2023 · 4 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information support: commercial Support request from paid users

Comments

@vishal-kadmos
Copy link

vishal-kadmos commented Jun 30, 2023

Order ID or Support key 💳 (optional)

52198

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

The problem in depth 🔍

Observed two issues with datepicker + custom Text field component

#1. If with custom text field components, input props are not provided (see TODO comment in code sandbox attached), placement for datepicker popup does not align with anchored input element
Screenshot 2023-06-30 at 8 48 39 AM

#2. If I try to fix above popper placement issue with input props, datepicker rerenders/flickers
Screencast 2023-06-30 08-51-48.webm

here is attached code sandbox reproducible:

https://codesandbox.io/s/mui-datepicker-with-custom-textfield-issues-t8tr9w?file=/src/Datepicker.tsx

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

System:
    OS: macOS 13.4
  Binaries:
    Node: 20.0.0 - ~/.nvm/versions/node/v20.0.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 9.6.3 - ~/projects/kadmos/customer-portal/node_modules/.bin/npm
  Browsers:
    Chrome: 114.0.5735.198
    Edge: 113.0.1774.35
    Safari: 16.5
  npmPackages:
    @emotion/react: ^11.11.0 => 11.11.0
    @emotion/styled: ^11.11.0 => 11.11.0
    @mui/base:  5.0.0-beta.3
    @mui/core-downloads-tracker:  5.13.3
    @mui/material: ^5.13.3 => 5.13.3
    @mui/private-theming:  5.13.1
    @mui/styled-engine:  5.13.2
    @mui/styled-engine-sc: ^5.12.0 => 5.12.0
    @mui/system:  5.13.2
    @mui/types:  7.2.4
    @mui/utils:  5.13.1
    @mui/x-data-grid:  6.5.0
    @mui/x-data-grid-pro: ^6.5.0 => 6.5.0
    @mui/x-date-pickers:  6.5.0
    @mui/x-date-pickers-pro: ^6.5.0 => 6.5.0
    @mui/x-license-pro:  6.0.4
    @types/react: ^18.2.7 => 18.2.7
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    styled-components: ^5.3.11 => 5.3.11
    typescript: ^5.0.4 => 5.0.4

node v18.4.0
browser: Chrome latest

"@emotion/react": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@mui/material": "^5.13.3",
"@mui/styled-engine-sc": "^5.12.0",
"@mui/x-date-pickers-pro": "^6.5.0",

@vishal-kadmos vishal-kadmos added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Jun 30, 2023
@vishal-kadmos vishal-kadmos changed the title [question] Datepicker flickers with custom textfield component [bug] Datepicker flickers with custom textfield component Jun 30, 2023
@flaviendelangle
Copy link
Member

Hi,

Not sure it will solve your problem, but you are defining your WrappedMyTextField inside the DatePicker component.
So everytime DatePicker re-renders, a new WrappedMyTextField component is created and React remounts it's instance.

You should never create components inside another one like that, it will always lead to unwanted behavior.

@flaviendelangle flaviendelangle added status: waiting for author Issue with insufficient information component: pickers This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 30, 2023
@flaviendelangle flaviendelangle changed the title [bug] Datepicker flickers with custom textfield component [pickers] Datepicker flickers with custom textfield component Jun 30, 2023
@vishal-kadmos
Copy link
Author

Agree. but this does not solve core issue. Any help?

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Jul 1, 2023
@flaviendelangle
Copy link
Member

The InputProps contains the ref used to place the popper.
If you don't pass it to the TextField, it is normal that the placement is wrong.
If you do pass it to the TextField, I don't see any flickering if the component is correctly defined.
Updated example

@flaviendelangle flaviendelangle added the status: waiting for author Issue with insufficient information label Aug 1, 2023
@github-actions
Copy link

github-actions bot commented Aug 8, 2023

Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.

@github-actions github-actions bot closed this as completed Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information support: commercial Support request from paid users
Projects
None yet
Development

No branches or pull requests

2 participants