reactjs / react-autocomplete

WAI-ARIA compliant React autocomplete (combobox) component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Limit items show in the menu

jmarcosvillar opened this issue · 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.

+1 would like to see this feature

@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);
  }
}