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

Components["List"] expects the ref to be an HTMLDivElement in Typescript [BUG] #864

Open
allanRubenstein opened this issue Mar 16, 2023 · 3 comments
Labels
bug Something isn't working hacktoberfest This issue is suitable for the hacktoberfest ;)

Comments

@allanRubenstein
Copy link

Describe the bug
When using typescript and a custom List, Typescript throws an error and says it expects an HTMLDivElement when you try to pass the ref to anything else, for example an unordered list.

Reproduction
https://codesandbox.io/s/virtualized-custom-list-and-item-type-issue-g3irvh?file=/App.tsx:415-433

To Reproduce
Steps to reproduce the behavior:

  1. Create a component of type Components["List"] following the example on https://virtuoso.dev/customize-structure/
  2. Try and pass the ref to an element other than a div
  3. See error on the ref

Expected behavior
The ref is able to be passed to any html element.

Screenshots
Screenshot 2023-03-16 at 4 11 52 PM

@allanRubenstein allanRubenstein added the bug Something isn't working label Mar 16, 2023
@petyosi
Copy link
Owner

petyosi commented Mar 17, 2023

True, do you think you can send a PR for that? Worth doing so for the Items, too.

@petyosi petyosi added the hacktoberfest This issue is suitable for the hacktoberfest ;) label Sep 7, 2023
@singhAmandeep007
Copy link

@allanRubenstein

Here is a work around

const VirtuosoList: Components["List"] = forwardRef((props, ref) => {
  return (
    <ul
      aria-labelledby="locations-list-label"
      aria-describedby="locations-list-description"
      ref={ref as React.RefObject<HTMLUListElement>}
      {...(props as React.HTMLAttributes<HTMLUListElement>)}
    >
      {props.children}
    </ul>
  );
});

@aPinix
Copy link

aPinix commented Sep 26, 2024

@allanRubenstein

Here is a work around

const VirtuosoList: Components["List"] = forwardRef((props, ref) => {
  return (
    <ul
      aria-labelledby="locations-list-label"
      aria-describedby="locations-list-description"
      ref={ref as React.RefObject<HTMLUListElement>}
      {...(props as React.HTMLAttributes<HTMLUListElement>)}
    >
      {props.children}
    </ul>
  );
});

I can't seem to use this, at least in the version "react-virtuoso": "^4.10.4".

I'm using VirtuosoGrid by the way.

I get an error "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops."

Can anybody help? Thanks in advance ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hacktoberfest This issue is suitable for the hacktoberfest ;)
Projects
None yet
Development

No branches or pull requests

4 participants