Skip to content

Commit cd51e31

Browse files
committed
IconPicker - default search with . Additional prop to switch the search to
1 parent cea1fba commit cd51e31

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

docs/documentation/docs/controls/IconPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ The IconPicker component can be configured with the following properties:
5454
| panelClassName | boolean | no | If provided, additional class name will be added to the picker panel |
5555
| currentIcon | string | no | Specifies default selected icon |
5656
| renderOption | `dialog`, `panel` | no | Specifies how to render list of Icons, Values : 'Panel' or 'Dialog' defualt value 'Panel' |
57+
| useStartsWithSearch | boolean | no | Specifies if we need to use `startsWith` when searching for the icons. |
5758

5859
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/IconPicker)

src/controls/iconPicker/IIconPickerProps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ export interface IIconPickerProps {
3131
* irender option: panel, dialog
3232
*/
3333
renderOption?: 'panel' | 'dialog';
34+
/**
35+
* Specifies if we need to use `startsWith` when searching for the icons.
36+
* Default: false
37+
*/
38+
useStartsWithSearch?: boolean;
3439
}

src/controls/iconPicker/IconPicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class IconPicker extends React.Component<IIconPickerProps, IIconPickerSta
138138
private onChange = (newValue?: string): void => {
139139
let items: string[];
140140
if (newValue && newValue.trim().length > 2) {
141-
items = this._fluentIconsService.search(newValue); /*IconNames.Icons.filter(item => {
141+
items = this._fluentIconsService.search(newValue, this.props.useStartsWithSearch); /*IconNames.Icons.filter(item => {
142142
return item.toLocaleLowerCase().indexOf(newValue.toLocaleLowerCase()) !== -1;
143143
});*/
144144
} else {

src/services/FluentIconsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class FluentIconsService {
2020

2121
public search = (query: string, startsWith?: boolean): string[] => {
2222
const lowerCasedQuery = query.toLowerCase();
23-
return this._iconNames.filter(name => startsWith === false ? name.toLowerCase().indexOf(lowerCasedQuery) !== -1 : name.toLowerCase().indexOf(query) === 0);
23+
return this._iconNames.filter(name => !startsWith ? name.toLowerCase().indexOf(lowerCasedQuery) !== -1 : name.toLowerCase().indexOf(query) === 0);
2424
}
2525
}
2626

0 commit comments

Comments
 (0)