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

Limit items show in the menu

Open jmarcosvillar opened this issue 6 years ago • 2 comments

Actually, I am using a +900 list, but I only want to show 10 records on the menu. But when I try to scroll down with a modified children list on renderMenu, it crash.

jmarcosvillar avatar Jan 09 '19 15:01 jmarcosvillar

+1 would like to see this feature

ilya-section4 avatar Feb 21 '19 16:02 ilya-section4

@jmarcosvillar @ilya-section4 work-arround/solution:

class LimitedAutocomplete extends Autocomplete {
  getFilteredItems(props) {
    let items = props.items

    if (props.shouldItemRender) {
      items = items.filter((item) => (
        props.shouldItemRender(item, props.value)
      ))
    }

    if (props.sortItems) {
      items.sort((a, b) => (
        props.sortItems(a, b, props.value)
      ))
    }

    return items.slice(0, props.limitItemsLength);
  }
}

Or

class LimitedAutocomplete extends Autocomplete {
  getFilteredItems(props) {
    const items = Autocomplete.prototype.getFilteredItems.call(this, props);
    return items.slice(0, props.limitItemsLength);
  }
}

FedeG avatar Jul 16 '19 17:07 FedeG