
Searchbar React Component
Searchbar React component represents Framework7’s Searchbar component.
Searchbar Components
There are following components included:
**Searchbar**/**F7Searchbar**
Searchbar Properties
You can pass all parameters in single params property or use separate props for each parameter to specify them via component attributes:
| Prop | Type | Default | Description |
|---|---|---|---|
| <Searchbar> properties | |||
| --- | --- | --- | --- |
| init | boolean | true | Initializes Searchbar |
| value | string number | Allows to specify Searchbar input’s value. Can be usefule when used with customSearch enabled |
|
| form | boolean | true | Main searchbar element will be used as a form tag instead of div |
| placeholder | string | “Search” | Input placeholder text |
| disableButton | boolean | true | Enables disable button |
| disableButtonText | string | Cancel | Disable button text |
| clearButton | boolean | true | Enables searchbar input clear button |
| expandable | boolean | false | Enables expandable searchbar |
| inline | boolean | false | Enables inline searchbar |
| searchContainer | string object | CSS selector or HTML element of list block to search | |
| searchIn | string | .item-title | CSS selector of List View element’s field where we need to search. Usually we search through element titles (‘.item-title’). It is also to pass few elements for search like ‘.item-title, .item-text’ |
| searchItem | string | li | CSS selector of single search item. If we do a search in List View, then it must be a single list element li |
| searchGroup | string | .list-group | CSS selector of group element. Used when hideGroups enabled to hide groups. If we do a search in List View, then it usually a list group. |
| searchGroupTitle | string | .list-group-title, .item-divider | CSS selector of group titles and dividers. Used when hideDividers enabled to hide group titles and dividers. If we do a search in List View, then it usually a list group title or list item divider. |
| foundEl | string object | .searchbar-found | CSS selector or HTMLElement of searchbar “found” element. If not specified, searchbar will look for .searchbar-found element on page |
| notFoundEl | string object | .searchbar-not-found | CSS selector or HTMLElement of searchbar “not-found” element. If not specified, searchbar will look for .searchbar-not-found element on page |
| backdrop | boolean | Enables searchbar backdrop element. By default, disabled for Aurora theme or for inline searchbar | |
| backdropEl | string object | CSS selector or HTMLElement of searchbar backdrop element. If not passed and backdrop parameter is true then it will look for .searchbar-backdrop element. In case none found it will create one automatically |
|
| ignore | string | .searchbar-ignore | CSS selector for items to be ignored by searchbar and always present in search results |
| customSearch | boolean | false | When enabled searchbar will not search through any of list blocks specified by search-container and you will be able to use custom search functionality, for example, for calling external APIs with search results and for displaying them manually |
| removeDiacritics | boolean | false | Enable to remove/replace diacritics (á, í, ó, etc.) during search |
| hideDividers | boolean | true | If enabled, then search will consider item dividers and group titles and hide them if there are no found items right after them |
| hideGroups | boolean | true | If enabled, then search will consider list view groups hide them if there are no found items inside of these groups |
| noShadow | boolean | false | Disable shadow rendering for MD theme |
| noHairline | boolean | false | Disable searchbar bottom thin border (hairline) for iOS theme |
Searchbar Methods
| <Searchbar> methods | |
|---|---|
| .search(query) | Force searchbar to search passed query |
| .enable() | Enable/activate searchbar |
| .disable() | Disable/deactivate searchbar |
| .toggle() | Toggle searchbar |
| .clear() | Clear search query and update results |
Searchbar Events
| Event | Arguments | Description |
|---|---|---|
| <Searchbar> events | ||
| --- | --- | --- |
| searchbarSearch | (searchbar, query, previousQuery) | Event will be triggered during search (search field change). As an arguments event receives searchbar instance, search query and previous query |
| searchbarClear | (searchbar, previousQuery) | Event will be triggered when user clicks on Searchbar input “clear” button. As an arguments event receives searchbar instance and previous query |
| searchbarEnable | (searchbar) | Event will be triggered when Searchbar becomes active |
| searchbarDisable | (searchbar) | Event will be triggered when Searchbar becomes inactive/disabled |
| change | (event) | Event will be triggered when “change” event occurs on searchbar input element |
| input | (event) | Event will be triggered when “input” event occurs on searchbar input element |
| focus | (event) | Event will be triggered when “focus” event occurs on searchbar input element |
| blur | (event) | Event will be triggered when “blur” event occurs on searchbar input element |
| clickClear | (event) | Event will be triggered when user clicks on input “clear” button |
| clickDisable | (event) | Event will be triggered when user clicks on searchbar disable button |
Searchbar Slots
Searchbar React component has additional slots for custom elements:
**default**- element will be inserted as a child of<div class="searchbar-inner">element in the end. Same as**inner-end**slot**before-inner**- element will be inserted right before<div class="searchbar-inner">element**after-inner**- element will be inserted right after<div class="searchbar-inner">element**inner-start**- element will be inserted as a child of<div class="searchbar-inner">element in the beginning**inner-end**- element will be inserted as a child of<div class="searchbar-inner">element in the end**input-wrap-start**- element will be inserted as a child of<div class="searchbar-input-wrap">element in the beginning**input-wrap-end**- element will be inserted as a child of<div class="searchbar-input-wrap">element in the end
Without Slots:
1. <Searchbar
2. disableLinkText="Cancel"
3. placeholder="Search in items"
4. clearButton={true}
5. ></Searchbar>
7. {/* Renders to: */}
9. <form class="searchbar">
10. <div class="searchbar-inner">
11. <div class="searchbar-input-wrap">
12. <input type="search" placeholder="Search">
13. <i class="searchbar-icon"></i>
14. <span class="input-clear-button"></span>
15. </div>
16. <span class="searchbar-disable-button">Cancel</span>
17. </div>
18. </form>
With Slots:
1. <Searchbar
2. disableLinkText="Cancel"
3. placeholder="Search in items"
4. clearButton={true}
5. >
6. <div slot="inner-start">Inner Start</div>
7. <div slot="inner-end">Inner End</div>
8. <div slot="input-wrap-start">Input Wrap Start</div>
9. <div slot="input-wrap-end">Input Wrap End</div>
10. <div slot="before-inner">Before Inner</div>
11. <div slot="after-inner">After Inner</div>
12. </Searchbar>
14. {/* Renders to: */}
16. <form class="searchbar">
17. <div slot="before-inner">Before Inner</div>
18. <div class="searchbar-inner">
19. <div slot="inner-start">Inner Start</div>
20. <div class="searchbar-input-wrap">
21. <div slot="input-wrap-start">Input Wrap Start</div>
22. <input type="search" placeholder="Search">
23. <i class="searchbar-icon"></i>
24. <span class="input-clear-button"></span>
25. <div slot="input-wrap-end">Input Wrap End</div>
26. </div>
27. <span class="searchbar-disable-button">Cancel</span>
28. <div slot="inner-end">Inner End</div>
29. </div>
30. <div slot="after-inner">After Inner</div>
31. </form>
Access To Searchbar Instance
If you use automatic initalization to init Searchbar (with init={true} prop) and need to use Searchbar API you can access its initialized instance by accessing **.f7Searchbar** component’s property.
Examples
Usual Searchbar
1. export default () => (
2. <Page>
3. <Navbar title="Searchbar">
4. <Subnavbar inner={false}>
5. <Searchbar
6. searchContainer=".search-list"
7. searchIn=".item-title"
8. disableButton={!this.$theme.aurora}
9. ></Searchbar>
10. </Subnavbar>
11. </Navbar>
12. <List className="searchbar-not-found">
13. <ListItem title="Nothing found" />
14. </List>
15. <List className="search-list searchbar-found">
16. <ListItem title="Acura" />
17. <ListItem title="Audi" />
18. <ListItem title="BMW" />
19. <ListItem title="Cadillac " />
20. <ListItem title="Chevrolet " />
21. <ListItem title="Chrysler " />
22. <ListItem title="Dodge " />
23. <ListItem title="Ferrari " />
24. <ListItem title="Ford " />
25. <ListItem title="GMC " />
26. <ListItem title="Honda" />
27. <ListItem title="Hummer" />
28. <ListItem title="Hyundai" />
29. <ListItem title="Infiniti " />
30. <ListItem title="Isuzu " />
31. <ListItem title="Jaguar " />
32. <ListItem title="Jeep " />
33. <ListItem title="Kia" />
34. <ListItem title="Lamborghini " />
35. <ListItem title="Land Rover" />
36. <ListItem title="Lexus " />
37. <ListItem title="Lincoln " />
38. <ListItem title="Lotus " />
39. <ListItem title="Mazda" />
40. <ListItem title="Mercedes-Benz" />
41. <ListItem title="Mercury " />
42. <ListItem title="Mitsubishi" />
43. <ListItem title="Nissan " />
44. <ListItem title="Oldsmobile " />
45. <ListItem title="Peugeot " />
46. <ListItem title="Pontiac " />
47. <ListItem title="Porsche" />
48. <ListItem title="Regal" />
49. <ListItem title="Saab " />
50. <ListItem title="Saturn " />
51. <ListItem title="Subaru " />
52. <ListItem title="Suzuki " />
53. <ListItem title="Toyota" />
54. <ListItem title="Volkswagen" />
55. <ListItem title="Volvo" />
56. </List>
57. </Page>
58. );
Expandable Searchbar
1. export default () => (
2. <Page>
3. <Navbar title="Searchbar">
4. <NavRight>
5. <Link searchbarEnable=".searchbar-demo" iconIos="f7:search" iconAurora="f7:search" iconMd="material:search"></Link>
6. </NavRight>
7. <Searchbar
8. className="searchbar-demo"
9. expandable
10. searchContainer=".search-list"
11. searchIn=".item-title"
12. disableButton={!this.$theme.aurora}
13. ></Searchbar>
14. </Navbar>
15. <List className="searchbar-not-found">
16. <ListItem title="Nothing found" />
17. </List>
18. <List className="search-list searchbar-found">
19. <ListItem title="Acura" />
20. <ListItem title="Audi" />
21. <ListItem title="BMW" />
22. <ListItem title="Cadillac " />
23. <ListItem title="Chevrolet " />
24. <ListItem title="Chrysler " />
25. <ListItem title="Dodge " />
26. <ListItem title="Ferrari " />
27. <ListItem title="Ford " />
28. <ListItem title="GMC " />
29. <ListItem title="Honda" />
30. <ListItem title="Hummer" />
31. <ListItem title="Hyundai" />
32. <ListItem title="Infiniti " />
33. <ListItem title="Isuzu " />
34. <ListItem title="Jaguar " />
35. <ListItem title="Jeep " />
36. <ListItem title="Kia" />
37. <ListItem title="Lamborghini " />
38. <ListItem title="Land Rover" />
39. <ListItem title="Lexus " />
40. <ListItem title="Lincoln " />
41. <ListItem title="Lotus " />
42. <ListItem title="Mazda" />
43. <ListItem title="Mercedes-Benz" />
44. <ListItem title="Mercury " />
45. <ListItem title="Mitsubishi" />
46. <ListItem title="Nissan " />
47. <ListItem title="Oldsmobile " />
48. <ListItem title="Peugeot " />
49. <ListItem title="Pontiac " />
50. <ListItem title="Porsche" />
51. <ListItem title="Regal" />
52. <ListItem title="Saab " />
53. <ListItem title="Saturn " />
54. <ListItem title="Subaru " />
55. <ListItem title="Suzuki " />
56. <ListItem title="Toyota" />
57. <ListItem title="Volkswagen" />
58. <ListItem title="Volvo" />
59. </List>
60. </Page>
61. );
