Add regex expression option to autocompleters (https://github.com/woocommerce/woocommerce-admin/pull/1380)

This commit is contained in:
Joshua T Flowers 2019-01-24 09:35:47 +08:00 committed by GitHub
parent 5b46862584
commit 23f807c0a4
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -23,6 +23,9 @@ export default {
options() {
return wcSettings.dataEndpoints.countries || [];
},
getSearchExpression( query ) {
return '^' + query;
},
getOptionKeywords( country ) {
return [ country.code, decodeEntities( country.name ) ];
},