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

[data grid] AutoComplete looses focus on first selection after user starts typing #13702

Closed
BeckmannArmin opened this issue Jul 2, 2024 · 11 comments
Assignees
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Filtering on header Related to the header filtering (Pro) feature status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@BeckmannArmin
Copy link

BeckmannArmin commented Jul 2, 2024

The problem in depth

Hey,

We are using custom filter operators in our application to render a Autocomplete inside the header filter cell to let the user search and select multiple values to filter the data inside the DataGrid.

However when using a Autocomplete as a header filter only every second input is registered. The component itself seems to loose its focus when you first focus it and then start typing on your keyboard.

I tried to debug it and stumbled across the layoutEffect function inside GridHeaderFilterCell.js (line 92-102)

React.useLayoutEffect(() => { if (hasFocus && !isMenuOpen) { let focusableElement = cellRef.current.querySelector('[tabindex="0"]'); if (isEditing && InputComponent) { focusableElement = inputRef.current; } const elementToFocus = focusableElement || cellRef.current; elementToFocus?.focus(); apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0; } }, [InputComponent, apiRef, hasFocus, isEditing, isMenuOpen]);

Maybe this is the right palce to look for.

Here is an example

Steps to reproduce:

  1. Select the rating field
  2. Start typing -> The popover should disappear and the field blurs.
  3. After selecting it again (when already selected) it seems to work
  4. As soon as you select another textfield and go back to the rating field (or any other field with the Autocomplete component) it does not work anymore.

We are expecting that the user can start typing as soon as he selects the field.

Your environment

`npx @mui/envinfo`
 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Search keywords: autocomplete
Order ID: 83002

@BeckmannArmin BeckmannArmin added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Jul 2, 2024
@KenanYusuf KenanYusuf added the component: data grid This is the name of the generic UI component, not the React module! label Jul 2, 2024
@KenanYusuf KenanYusuf changed the title [DataGridPremium] AutoComplete looses focus on first selection after user starty typing [DataGridPremium] AutoComplete looses focus on first selection after user starts typing Jul 4, 2024
@KenanYusuf KenanYusuf assigned KenanYusuf and unassigned KenanYusuf Jul 4, 2024
@KenanYusuf KenanYusuf added the feature: Filtering on header Related to the header filtering (Pro) feature label Jul 5, 2024
@KenanYusuf
Copy link
Contributor

Thanks for reporting the issue @BeckmannArmin, I have also managed to reproduce the issue using your example, and my own example forked from the custom header filter demo.

I will add this to the board for prioritisation.

@KenanYusuf KenanYusuf added bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 5, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Jul 5, 2024
@BeckmannArmin
Copy link
Author

Thanks for reporting the issue @BeckmannArmin, I have also managed to reproduce the issue using your example, and my own example forked from the custom header filter demo.

I will add this to the board for prioritisation.

Thanks. Sounds "good" that this is an issue for everyone and not on our end. Will you update here once the issue is resolved?

@KenanYusuf
Copy link
Contributor

@BeckmannArmin yes, we will update this issue when a fix is available.

@KenanYusuf
Copy link
Contributor

This issue might be related to #13734

@michelengelen michelengelen added the support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ label Jul 15, 2024
@michelengelen michelengelen changed the title [DataGridPremium] AutoComplete looses focus on first selection after user starts typing [data grid] AutoComplete looses focus on first selection after user starts typing Jul 15, 2024
@BeckmannArmin
Copy link
Author

@KenanYusuf Are there any updates? Our users are wating desperately for a fix. We re running our app in a productive environment where every clicks costs time (money).

@KenanYusuf KenanYusuf moved this from 🆕 Needs refinement to 🔖 Ready in MUI X Data Grid Aug 1, 2024
@KenanYusuf KenanYusuf self-assigned this Aug 1, 2024
@KenanYusuf KenanYusuf moved this from 🔖 Ready to 🏗 In progress in MUI X Data Grid Aug 1, 2024
@KenanYusuf
Copy link
Contributor

@KenanYusuf Are there any updates? Our users are wating desperately for a fix. We re running our app in a productive environment where every clicks costs time (money).

Working on a fix for this @BeckmannArmin - should be available soon.

@KenanYusuf
Copy link
Contributor

Hey @BeckmannArmin

@MBilalShafi took a look at your example and managed to fix the issue you were seeing by passing inputRef={props.inputRef} to the TextField component.

const renderInput = useCallback((params) => {
  return (
    <TextField
      {...params}
      variant="standard" />
++    inputRef={props.inputRef}
    />
  );
}, []);

Hopefully that solves it, but let me know if you're still experiencing the problem.

@KenanYusuf KenanYusuf added the status: waiting for author Issue with insufficient information label Aug 1, 2024
@BeckmannArmin
Copy link
Author

BeckmannArmin commented Aug 6, 2024

Hey @BeckmannArmin

@MBilalShafi took a look at your example and managed to fix the issue you were seeing by passing inputRef={props.inputRef} to the TextField component.

const renderInput = useCallback((params) => {
  return (
    <TextField
      {...params}
      variant="standard" />
++    inputRef={props.inputRef}
    />
  );
}, []);

Hopefully that solves it, but let me know if you're still experiencing the problem.

 inputRef={props.inputRef}

inputRef does not exist in the props validation. Neither does it in the params for the renderInput function.
Where did you get it from?

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Aug 6, 2024
@BeckmannArmin
Copy link
Author

BeckmannArmin commented Aug 6, 2024

Could you provide or adjust the example from above accordingly? @KenanYusuf

@michelengelen
Copy link
Member

Hey @BeckmannArmin ... The inputRef is coming from the GridFilterOperator['InputComponent'] type. We type this as React.JSXElementConstructor<any>, so it is not clear from the types immediately.
We do pass the inputRef during the internal rendering of the GridHeaderFilterCell component.
Reference:

<InputComponent
apiRef={apiRef}
item={item}
inputRef={inputRef}
applyValue={applyFilterChanges}
onFocus={() => apiRef.current.startHeaderFilterEditMode(colDef.field)}

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 12, 2024
Copy link

The issue has been inactive for 7 days and has been automatically closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Filtering on header Related to the header filtering (Pro) feature status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/
Projects
Status: 🏗 In progress
Development

No branches or pull requests

3 participants