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.

Is it possible to prepend custom elements to the list?

See original GitHub issue

It would be helpful to add a search bar for example, similarly to what twitter does for messages search: Screen Shot 2020-02-17 at 10 39 21

In reactWindow I used to do it this way:

  1. Add a paddingTop to the list
    const Item = ({ index, style }) => {
      const item = items[index];

      return (
        <div
          style={{
            ...style,
            top: `${parseFloat(style.top) + topPadding}px`
          }}
        >
          <ItemRendrer item={item} />
        </div>
      );
    };
  1. Then, using the list container renderer, I place the customElement at top of the list
const innerElementType = React.forwardRef(({ style, ...rest }, ref) => (
      <div>
        {customElement}
        <div
          ref={ref}
          style={{
            ...style,
            height: `${parseFloat(style.height) + topPadding}px`
          }}
          {...rest}
        />
      </div>
    ));

My first reaction was trying to replicate the same workaround in Virtuoso but found that the style is not passed down as a prop in ItemRendrer. Maybe there is a better/cleaner way.

Thank you by the way for the this awesome piece of software!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
petyosicommented, Feb 17, 2020

I am considering an optional header component, in the same way as the footer. Meanwhile, you can easily do something like this (which is not very elegant, but works:): https://stackblitz.com/edit/react-y6fim2?file=example.js

Let me know what you think about it.

1reaction
petyosicommented, May 1, 2020

@mdegrees - no, not a good idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to add elements within a custom element without ...
Basically, the custom element has to be able to have any number of elements within, like an unordered list ( <ul> ) which...
Read more >
Element.prepend() - Web APIs - MDN Web Docs
The Element.prepend() method inserts a set of Node objects or string objects before the first child of the Element.
Read more >
Custom elements - The Modern JavaScript Tutorial
We can create custom HTML elements, described by our class, with its own methods and properties, ... Here's a sketch with the full...
Read more >
.prepend() | jQuery API Documentation
A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert at the beginning of each element in...
Read more >
Python List .append() – How to Add an Item to a List in Python
list.insert() – inserts a single element anywhere in the list. · list.append() – always adds items (strings, numbers, lists) at the end of...
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