question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add a disableTags prop for Autocomplete

See original GitHub issue

I’m not sure that is this a feature request or a bug fix in this example of Autocomplete component you used renderTags={() => null} to disable showing tags but when we do this tags will not be disabled completely and the handleKeyDown listener will be attached to component which cause removing selected elements using backspace in search box which is not which we need in this example

I think adding a disableTag={true} prop to AutoComplete component would be a good solution

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jun 6, 2020

@MHA15 Thanks for raising, this is concerning:

  1. Navigate to http://0.0.0.0:3000/components/autocomplete#githubs-picker
  2. Open the picker
  3. Press <kbd>ArrowLeft</kbd>
  4. 💥 TypeError: Cannot read property 'focus' of null

I think that the rendering logic of useAutocomplete should be more resilient, it should support missing tags. While I appreciate your proposal around disableTag, if feels that it’s something that is specific to the Autocomplete component. If we can get the same outcome with renderTags={() => null}, I think that we should rather go in this direction, it’s more explicit.

What do you think of this fix, considering a missing item as disabled? Do you want to work on a pull request? We would also need a regression test 😃.

diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index 3a7001d2d..661a812d8 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -265,7 +265,7 @@ export default function useAutocomplete(props) {
       // Same logic as MenuList.js
       const nextFocusDisabled = disabledItemsFocusable
         ? false
-        : option && (option.disabled || option.getAttribute('aria-disabled') === 'true');
+        : !option || option.disabled || option.getAttribute('aria-disabled') === 'true';

       if ((option && !option.hasAttribute('tabindex')) || nextFocusDisabled) {
         // Move to the next element.
@@ -568,10 +568,10 @@ export default function useAutocomplete(props) {

       // Same logic as MenuList.js
       if (
-        option &&
-        (!option.hasAttribute('tabindex') ||
-          option.disabled ||
-          option.getAttribute('aria-disabled') === 'true')
+        !option ||
+        !option.hasAttribute('tabindex') ||
+        option.disabled ||
+        option.getAttribute('aria-disabled') === 'true'
       ) {
         nextFocus += direction === 'next' ? 1 : -1;
       } else {
0reactions
matthenschkecommented, Jun 15, 2020

Just submitted a pr based off of your suggestion @oliviertassinari, does anyone have any advice on mastering the material-ui codebase? https://github.com/mui-org/material-ui/pull/21460

Read more comments on GitHub >

github_iconTop Results From Across the Web

add a disableTags prop for Autocomplete #21333 - GitHub
bug Something isn't working component: autocomplete This is the name of the generic UI component, not the React module! good first issue ...
Read more >
A Guide on Material UI AutoComplete in React - Refine Dev
When you add the freeSolo prop to the <Autocomplete /> component, it enables the text field to accept undetermined values.
Read more >
How can I add unique keys to React/MUI Autocomplete ...
If it still doesn't work, check your props order, you need to declare the key prop ... Then it will be overridden by...
Read more >
How to Use The Autocomplete Component in Material-UI
The Material-UI docs describe the autocomplete as “a normal text input ... Then, in the Autocomplete component, we can add two more props....
Read more >
React Autocomplete component - Material UI - MUI
The autocomplete is a normal text input enhanced by a panel of suggested ... The prop is designed to cover the primary use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found