[Autocomplete] - Passing props to ListboxComponent

See original GitHub issue

Not sure if this is a bug or not.

I am trying to fetch more options when ListboxComponent scroll is at the bottom. Having issues with the custom ListboxComponent.

When I pass props I get a fowardRef warning and the list items won’t render correctly even tho fowardRef was used.

      ListboxComponent={listboxProps => (
        <ListboxComponent
          {...listboxProps}
          setIsScrollBottom={setIsScrollBottom}
        />
      )}
const ListboxComponent = forwardRef(function ListboxComponent({ setIsScrollBottom, ...rest }, ref) {
  return (
    <ul
      ref={ref}
      {...rest}
      onScroll={({ target }) =>
        setIsScrollBottom(target.scrollHeight - target.scrollTop === target.clientHeight)
      }
    />
  );
});

Demo https://codesandbox.io/s/jolly-matsumoto-ugs5d

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
WasiakSzymoncommented, Dec 14, 2021

After X long hours spent on trying do ‘hacks’ with scroll/fix warning type listBoxComponent props i couldn’t find any working way do handle that… the way which i’ve chosen is to use hook useAutocomplete and provide custom list box build based on material-ui components like <Typography component='li' /> (i wanted have the same style/look like material-ui autocomplete)

there is a good example (easy to convert to TypeScript) https://codesandbox.io/s/material-demo-0fbyb?file=/demo.js

in my case i only imported getRootProps( for parent div), getInputProps( for inputProps TextField) and everything works

1reaction
RustamYcommented, Nov 22, 2021

@ChrisWiles have you find a way to prevent the “jump to start” scrolling glitch? Hi, maybe:

ListboxProps={{
   onScroll: (event: React.SyntheticEvent) => {
      event.stopPropagation();
      const listboxNode = event.currentTarget;
      const savedScrollTop = listboxNode.scrollTop;
      const diff = Math.round(
         listboxNode.scrollHeight - savedScrollTop,
      );
      if (diff - 25 <= listboxNode.clientHeight) {
         const returnScrollTop = () => {
            setTimeout(() => {
               listboxNode.scrollTop = savedScrollTop;
            }, 0);
         };
         getData(returnScrollTop);
      }
   },
}}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing props to ListboxComponent #18822 - mui/material-ui
I am trying to fetch more options when ListboxComponent scroll is at the ... [Autocomplete] - Passing props to ListboxComponent #18822.
Read more >
MUI Autocomplete - render image in list - Stack Overflow
I figured this out: I just needed to add a custom ListboxComponent and pass it to the Autocomplete . Here's the custom component:...
Read more >
How to Style the Material-UI Autocomplete Component
Create a custom Popper and pass classes to it in the v4 style. I will show both techniques below. MUI v5 Autocomplete ListboxProps....
Read more >
A Guide on Material UI AutoComplete in React - Refine Dev
We'll discover the Material UI (MUI) AutoComplete component with examples. ... Getting Started with MUI Autocomplete; MUI Autocomplete props.
Read more >
Customizing the Material-UI Autocomplete Component
Do you want to build a full MUI app from beginning to end, learn every aspect of the sx prop, styled API, and...
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