React-select: Option for prefix-only search [feature request]

Created on 10 Oct 2017  路  2Comments  路  Source: JedWatson/react-select

Hi, this is an feature request to add an option to restrict searchable to only match the prefix of labels and values. For instance, I want to implement state selector for US states as shown in demo site http://jedwatson.github.io/react-select/ but restrict the search to only match prefix.

Currently, searchable option matches any substring, so if user enters "NO" to enter North Dakota, react-select also shows Illinois. Similarly, when user enter ND (as abbreviation of North Dakota), react-select shows Indiana.

screen shot 2017-10-09 at 9 52 03 pm
screen shot 2017-10-09 at 9 51 51 pm

For this type of input, we expect user to enter from the first character so it'd be great if react-select support an option to restrict search to only match prefix of words.

Most helpful comment

Hi @daisy1754 we do have a matchPos prop that you can set. If you set it to start it will only check the start of the string. Also if you would like to customize this you can pass in your own filterOptions prop. See docs for more info: https://github.com/JedWatson/react-select#advanced-filters. Does this work for you?

All 2 comments

Hi @daisy1754 we do have a matchPos prop that you can set. If you set it to start it will only check the start of the string. Also if you would like to customize this you can pass in your own filterOptions prop. See docs for more info: https://github.com/JedWatson/react-select#advanced-filters. Does this work for you?

Ah, this is exactly what I wanted. I don't know why I look over this.. Thanks @agirton !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Meesam picture Meesam  路  3Comments

batusai513 picture batusai513  路  3Comments

coder-guy22296 picture coder-guy22296  路  3Comments

pashap picture pashap  路  3Comments

MindRave picture MindRave  路  3Comments