react-autosuggest icon indicating copy to clipboard operation
react-autosuggest copied to clipboard

Sections with no suggestions are still rendered

Open gzzo opened this issue 7 years ago • 3 comments

The README states:

Note: Sections with no suggestions are not rendered.

However, sections with no suggestions are still rendered. This is clear here. The correct behavior should be to not render anything for a section without items.

gzzo avatar Sep 11 '18 20:09 gzzo

I've also encountered the same problem first thing to come to me to fix it would be to check the length of this.sectionsItems[sectionIndex] and if it's not larger than 0 return false; (or smaller than 1)

gijsbotje avatar Oct 05 '18 18:10 gijsbotje

Also having the same problem - anyone got a workaround?

ErisDS avatar Oct 18 '18 12:10 ErisDS

@ErisDS This is the workaround I'm using:

renderSuggestionsContainer({ containerProps, children, query }) {
    // we need to do this because of https://github.com/moroshko/react-autosuggest/issues/570
    const filteredChildren = children && children.filter(child => {
      const [ title, items ] = child.props.children
      return title.props.section.hits.length
    })

    return (
      <div {... containerProps}>
        {filteredChildren}
      </div>
    )
  }

gzzo avatar Oct 19 '18 20:10 gzzo