Searchbar - 图1

Searchbar Vue Component

Searchbar Vue component represents Framework7’s Searchbar component.

Searchbar Components

There are following components included:

  • **f7-searchbar**

Searchbar Properties

You can pass all parameters in single params property or use separate props for each parameter to specify them via component attributes:

PropTypeDefaultDescription
<f7-searchbar> properties
initbooleantrueInitializes Searchbar
valuestring
number
Allows to specify Searchbar input’s value. Can be usefule when used with custom-search enabled
formbooleantrueMain searchbar element will be used as a form tag instead of div
placeholderstring“Search”Input placeholder text
disable-buttonbooleantrueEnables disable button
disable-button-textstringCancelDisable button text
clear-buttonbooleantrueEnables searchbar input clear button
search-containerstring
object
CSS selector or HTML element of list block to search
search-instring.item-titleCSS 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’
search-itemstringliCSS selector of single search item. If we do a search in List View, then it must be a single list element li
search-groupstring.list-groupCSS selector of group element. Used when hide-groups enabled to hide groups. If we do a search in List View, then it usually a list group.
search-group-titlestring.list-group-title, .item-dividerCSS selector of group titles and dividers. Used when hide-dividers 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.
found-elstring
object
.searchbar-foundCSS selector or HTMLElement of searchbar “found” element. If not specified, searchbar will look for .searchbar-found element on page
not-found-elstring
object
.searchbar-not-foundCSS selector or HTMLElement of searchbar “not-found” element. If not specified, searchbar will look for .searchbar-not-found element on page
backdropbooleantrueEnables searchbar backdrop element
backdrop-elstring
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
ignorestring.searchbar-ignoreCSS selector for items to be ignored by searchbar and always present in search results
custom-searchbooleanfalseWhen 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
remove-diacriticsbooleanfalseEnable to remove/replace diacritics (á, í, ó, etc.) during search
hide-dividersbooleantrueIf enabled, then search will consider item dividers and group titles and hide them if there are no found items right after them
hide-groupsbooleantrueIf enabled, then search will consider list view groups hide them if there are no found items inside of these groups
no-shadowbooleanfalseDisable shadow rendering for MD theme
no-hairlinebooleanfalseDisable searchbar bottom thin border (hairline) for iOS theme

Searchbar Methods

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

EventArgumentsDescription
<f7-searchbar> events
searchbar:search(searchbar, query, previousQuery)Event will be triggered during search (search field change). As an arguments event receives searchbar instance, search query and previous query
searchbar:clear(searchbar, previousQuery)Event will be triggered when user clicks on Searchbar input “clear” button. As an arguments event receives searchbar instance and previous query
searchbar:enable(searchbar)Event will be triggered when Searchbar becomes active
searchbar:disable(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
click:clear(event)Event will be triggered when user clicks on input “clear” button
click:disable(event)Event will be triggered when user clicks on searchbar disable button

Searchbar Slots

Searchbar Vue 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. <f7-searchbar
  2. disable-link-text="Cancel"
  3. placeholder="Search in items"
  4. :clear-button="true"
  5. ></f7-searchbar>
  6. <!-- Renders to: -->
  7. <form class="searchbar">
  8. <div class="searchbar-inner">
  9. <div class="searchbar-input-wrap">
  10. <input type="search" placeholder="Search">
  11. <i class="searchbar-icon"></i>
  12. <span class="input-clear-button"></span>
  13. </div>
  14. <span class="searchbar-disable-button">Cancel</span>
  15. </div>
  16. </form>

With Slots:

  1. <f7-searchbar
  2. disable-link-text="Cancel"
  3. placeholder="Search in items"
  4. :clear-button="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. </f7-searchbar>
  13. <!-- Renders to: -->
  14. <form class="searchbar">
  15. <div slot="before-inner">Before Inner</div>
  16. <div class="searchbar-inner">
  17. <div slot="inner-start">Inner Start</div>
  18. <div class="searchbar-input-wrap">
  19. <div slot="input-wrap-start">Input Wrap Start</div>
  20. <input type="search" placeholder="Search">
  21. <i class="searchbar-icon"></i>
  22. <span class="input-clear-button"></span>
  23. <div slot="input-wrap-end">Input Wrap End</div>
  24. </div>
  25. <span class="searchbar-disable-button">Cancel</span>
  26. <div slot="inner-end">Inner End</div>
  27. </div>
  28. <div slot="after-inner">After Inner</div>
  29. </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. <f7-page>
  2. <f7-navbar title="Searchbar">
  3. <f7-subnavbar :inner="false">
  4. <f7-searchbar
  5. search-container=".search-list"
  6. search-in=".item-title"
  7. ></f7-searchbar>
  8. </f7-subnavbar>
  9. </f7-navbar>
  10. <f7-list class="searchbar-not-found">
  11. <f7-list-item title="Nothing found"></f7-list-item>
  12. </f7-list>
  13. <f7-list class="search-list searchbar-found">
  14. <f7-list-item title="Acura"></f7-list-item>
  15. <f7-list-item title="Audi"></f7-list-item>
  16. <f7-list-item title="BMW"></f7-list-item>
  17. <f7-list-item title="Cadillac "></f7-list-item>
  18. <f7-list-item title="Chevrolet "></f7-list-item>
  19. <f7-list-item title="Chrysler "></f7-list-item>
  20. <f7-list-item title="Dodge "></f7-list-item>
  21. <f7-list-item title="Ferrari "></f7-list-item>
  22. <f7-list-item title="Ford "></f7-list-item>
  23. <f7-list-item title="GMC "></f7-list-item>
  24. <f7-list-item title="Honda"></f7-list-item>
  25. <f7-list-item title="Hummer"></f7-list-item>
  26. <f7-list-item title="Hyundai"></f7-list-item>
  27. <f7-list-item title="Infiniti "></f7-list-item>
  28. <f7-list-item title="Isuzu "></f7-list-item>
  29. <f7-list-item title="Jaguar "></f7-list-item>
  30. <f7-list-item title="Jeep "></f7-list-item>
  31. <f7-list-item title="Kia"></f7-list-item>
  32. <f7-list-item title="Lamborghini "></f7-list-item>
  33. <f7-list-item title="Land Rover"></f7-list-item>
  34. <f7-list-item title="Lexus "></f7-list-item>
  35. <f7-list-item title="Lincoln "></f7-list-item>
  36. <f7-list-item title="Lotus "></f7-list-item>
  37. <f7-list-item title="Mazda"></f7-list-item>
  38. <f7-list-item title="Mercedes-Benz"></f7-list-item>
  39. <f7-list-item title="Mercury "></f7-list-item>
  40. <f7-list-item title="Mitsubishi"></f7-list-item>
  41. <f7-list-item title="Nissan "></f7-list-item>
  42. <f7-list-item title="Oldsmobile "></f7-list-item>
  43. <f7-list-item title="Peugeot "></f7-list-item>
  44. <f7-list-item title="Pontiac "></f7-list-item>
  45. <f7-list-item title="Porsche"></f7-list-item>
  46. <f7-list-item title="Regal"></f7-list-item>
  47. <f7-list-item title="Saab "></f7-list-item>
  48. <f7-list-item title="Saturn "></f7-list-item>
  49. <f7-list-item title="Subaru "></f7-list-item>
  50. <f7-list-item title="Suzuki "></f7-list-item>
  51. <f7-list-item title="Toyota"></f7-list-item>
  52. <f7-list-item title="Volkswagen"></f7-list-item>
  53. <f7-list-item title="Volvo"></f7-list-item>
  54. </f7-list>
  55. </f7-page>

Expandable Searchbar

  1. <f7-page>
  2. <f7-navbar title="Searchbar">
  3. <f7-nav-right>
  4. <f7-link class="searchbar-enable" data-searchbar=".searchbar-demo" icon-ios="f7:search_strong" icon-md="material:search"></f7-link>
  5. </f7-nav-right>
  6. <f7-searchbar
  7. class="searchbar-demo"
  8. expandable
  9. search-container=".search-list"
  10. search-in=".item-title"
  11. ></f7-searchbar>
  12. </f7-navbar>
  13. <f7-list class="searchbar-not-found">
  14. <f7-list-item title="Nothing found"></f7-list-item>
  15. </f7-list>
  16. <f7-list class="search-list searchbar-found">
  17. <f7-list-item title="Acura"></f7-list-item>
  18. <f7-list-item title="Audi"></f7-list-item>
  19. <f7-list-item title="BMW"></f7-list-item>
  20. <f7-list-item title="Cadillac "></f7-list-item>
  21. <f7-list-item title="Chevrolet "></f7-list-item>
  22. <f7-list-item title="Chrysler "></f7-list-item>
  23. <f7-list-item title="Dodge "></f7-list-item>
  24. <f7-list-item title="Ferrari "></f7-list-item>
  25. <f7-list-item title="Ford "></f7-list-item>
  26. <f7-list-item title="GMC "></f7-list-item>
  27. <f7-list-item title="Honda"></f7-list-item>
  28. <f7-list-item title="Hummer"></f7-list-item>
  29. <f7-list-item title="Hyundai"></f7-list-item>
  30. <f7-list-item title="Infiniti "></f7-list-item>
  31. <f7-list-item title="Isuzu "></f7-list-item>
  32. <f7-list-item title="Jaguar "></f7-list-item>
  33. <f7-list-item title="Jeep "></f7-list-item>
  34. <f7-list-item title="Kia"></f7-list-item>
  35. <f7-list-item title="Lamborghini "></f7-list-item>
  36. <f7-list-item title="Land Rover"></f7-list-item>
  37. <f7-list-item title="Lexus "></f7-list-item>
  38. <f7-list-item title="Lincoln "></f7-list-item>
  39. <f7-list-item title="Lotus "></f7-list-item>
  40. <f7-list-item title="Mazda"></f7-list-item>
  41. <f7-list-item title="Mercedes-Benz"></f7-list-item>
  42. <f7-list-item title="Mercury "></f7-list-item>
  43. <f7-list-item title="Mitsubishi"></f7-list-item>
  44. <f7-list-item title="Nissan "></f7-list-item>
  45. <f7-list-item title="Oldsmobile "></f7-list-item>
  46. <f7-list-item title="Peugeot "></f7-list-item>
  47. <f7-list-item title="Pontiac "></f7-list-item>
  48. <f7-list-item title="Porsche"></f7-list-item>
  49. <f7-list-item title="Regal"></f7-list-item>
  50. <f7-list-item title="Saab "></f7-list-item>
  51. <f7-list-item title="Saturn "></f7-list-item>
  52. <f7-list-item title="Subaru "></f7-list-item>
  53. <f7-list-item title="Suzuki "></f7-list-item>
  54. <f7-list-item title="Toyota"></f7-list-item>
  55. <f7-list-item title="Volkswagen"></f7-list-item>
  56. <f7-list-item title="Volvo"></f7-list-item>
  57. </f7-list>
  58. </f7-page>