Material-ui: [Autocomplete] inputValue is always undefined in the renderOption prop

Created on 7 Nov 2019  路  2Comments  路  Source: mui-org/material-ui

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

In the renderOption prop, the second parameter's key, inputValue, is always sent as undefined.

Expected Behavior 馃

In the renderOption prop, the second parameter's key, inputValue, should be the text the user entered in the input field.

Steps to Reproduce 馃暪

https://codesandbox.io/s/material-demo-8q8zf?fontsize=14

Steps:

  1. Write something in the input field.
  2. The list is filtered accordingly, but in the console the value of inputValue is always undefined.

Context 馃敠

I'm trying to implement the Highlights behaviour described in the documentation: https://material-ui.com/components/autocomplete/#highlights.

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI/core | v4.6.0 |
| Material-UI/lab | v4.0.0-alpha.30 |
| React | v16.11.0 |
| Browser | Chrome (v77.0.3865.90) |

bug 馃悰 Autocomplete good first issue

All 2 comments

@raducanb Oops, thank you for the report. It's a leftover from the extraction of the core logic in useAutocomplete. What do you think of this diff?

diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.d.ts b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.d.ts
index 4160b0152..ad1503a2d 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.d.ts
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.d.ts
@@ -163,6 +163,7 @@ export default function useAutocomplete(
   getListboxProps: () => {};
   getOptionProps: ({ option, index }: { option: any; index: number }) => {};
   id: string;
+  inputValue: string;
   value: any;
   dirty: boolean;
   popupOpen: boolean;
diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index 72d7c84c3..396f5bb1a 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -731,6 +731,7 @@ export default function useAutocomplete(props) {
       };
     },
     id,
+    inputValue,
     value,
     dirty,
     popupOpen,

Do you want to work on a pull request? Thanks.

Sorry, I just saw the message. Thank you for the fast response and for the fix @AbdallahElroby & @oliviertassinari !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TimoRuetten picture TimoRuetten  路  3Comments

sys13 picture sys13  路  3Comments

mb-copart picture mb-copart  路  3Comments

ghost picture ghost  路  3Comments

activatedgeek picture activatedgeek  路  3Comments