Add regex expression option to autocompleters (https://github.com/woocommerce/woocommerce-admin/pull/1380)
This commit is contained in:
parent
5b46862584
commit
23f807c0a4
|
@ -193,7 +193,10 @@ export class Autocomplete extends Component {
|
|||
}
|
||||
}
|
||||
// create a regular expression to filter the options
|
||||
const search = new RegExp( escapeRegExp( query ), 'i' );
|
||||
const expression = 'undefined' !== typeof completer.getSearchExpression
|
||||
? completer.getSearchExpression( escapeRegExp( query ) )
|
||||
: escapeRegExp( query );
|
||||
const search = new RegExp( expression, 'i' );
|
||||
// filter the options we already have
|
||||
const filteredOptions = filterOptions( search, this.state.options, selected );
|
||||
// update the state
|
||||
|
|
|
@ -23,6 +23,9 @@ export default {
|
|||
options() {
|
||||
return wcSettings.dataEndpoints.countries || [];
|
||||
},
|
||||
getSearchExpression( query ) {
|
||||
return '^' + query;
|
||||
},
|
||||
getOptionKeywords( country ) {
|
||||
return [ country.code, decodeEntities( country.name ) ];
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue