Skip to content

Feature Request: Pass index of option to filterOption #3891

@togakangaroo

Description

@togakangaroo

For filterOption, you should pass a third parameter of the option index, possibly even a fourth with the entire option array itself.

Firstly, that more akin to what is expected for filtering callbacks

But more importantly that would allow you to implement filtering optimization logic such as

filterOption={(x, search, idx) => {
   if(!search) return idx < 25;
   return originalFilterOption(x, search, idx)
})

In fact I would go a step further and say also pass a mutable object as the "context" of a single pass through filtering all options. Then we could do

filterOption={(x, search, idx, allOptions, ctx) => {
   if(!search) return idx < 25;
   if(ctx.foundCount >= 25) return false
   const found = originalFilterOption(x, search, idx)
   if(found)
     ctx.foundCount = (ctx.foundCount || 0) + 1
   return found
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/reviewedIssue has recently been reviewed (mid-2020)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions