Skip to content

Commit

Permalink
Fixed #1335 - Add filterLocale property to ListBox
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Apr 17, 2020
1 parent 4907320 commit 804d421
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/listbox/ListBox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface ListBoxProps {
filterBy?: string;
filterMatchMode?: string;
filterPlaceholder?: string;
filterLocale?: string;
tabIndex?:string;
tooltip?: any;
tooltipOptions?: TooltipOptions;
Expand Down
12 changes: 7 additions & 5 deletions src/components/listbox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class ListBox extends Component {
filterBy: null,
filterMatchMode: 'contains',
filterPlaceholder: null,
filterLocale: undefined,
tabIndex: '0',
tooltip: null,
tooltipOptions: null,
Expand All @@ -51,6 +52,7 @@ export class ListBox extends Component {
filterBy: PropTypes.string,
filterMatchMode: PropTypes.string,
filterPlaceholder: PropTypes.string,
filterLocale: PropTypes.string,
tabIndex: PropTypes.string,
tooltip: PropTypes.string,
tooltipOptions: PropTypes.object,
Expand Down Expand Up @@ -242,10 +244,10 @@ export class ListBox extends Component {
}

filter(option) {
let filterValue = this.state.filter.trim().toLowerCase();
let optionLabel = this.getOptionLabel(option);
let filterValue = this.state.filter.trim().toLocaleLowerCase(this.props.filterLocale);
let optionLabel = this.getOptionLabel(option).toLocaleLowerCase(this.props.filterLocale);

return optionLabel.toLowerCase().indexOf(filterValue.toLowerCase()) > -1;
return optionLabel.indexOf(filterValue) > -1;
}

hasFilter() {
Expand All @@ -269,9 +271,9 @@ export class ListBox extends Component {

if (this.props.options) {
if (this.hasFilter()) {
let filterValue = this.state.filter.trim().toLowerCase();
let filterValue = this.state.filter.trim().toLocaleLowerCase(this.props.filterLocale)
let searchFields = this.props.filterBy ? this.props.filterBy.split(',') : [this.props.optionLabel || 'label'];
items = FilterUtils.filter(items, searchFields, filterValue, this.props.filterMatchMode);
items = FilterUtils.filter(items, searchFields, filterValue, this.props.filterMatchMode, this.props.filterLocale);
}

items = items.map((option, index) => {
Expand Down

0 comments on commit 804d421

Please sign in to comment.