Searchbar - 图1

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:

PropTypeDefaultDescription
<Searchbar> properties
initbooleantrueInitializes Searchbar
valuestring
number
Allows to specify Searchbar input’s value. Can be usefule when used with customSearch enabled
formbooleantrueMain searchbar element will be used as a form tag instead of div
placeholderstring“Search”Input placeholder text
disableButtonbooleantrueEnables disable button
disableButtonTextstringCancelDisable button text
clearButtonbooleantrueEnables searchbar input clear button
expandablebooleanfalseEnables expandable searchbar
inlinebooleanfalseEnables inline searchbar
searchContainerstring
object
CSS selector or HTML element of list block to search
searchInstring.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’
searchItemstringliCSS selector of single search item. If we do a search in List View, then it must be a single list element li
searchGroupstring.list-groupCSS 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.
searchGroupTitlestring.list-group-title, .item-dividerCSS 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.
foundElstring
object
.searchbar-foundCSS selector or HTMLElement of searchbar “found” element. If not specified, searchbar will look for .searchbar-found element on page
notFoundElstring
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
backdropbooleanEnables searchbar backdrop element. By default, disabled for Aurora theme or for inline searchbar
backdropElstring
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
customSearchbooleanfalseWhen 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
removeDiacriticsbooleanfalseEnable to remove/replace diacritics (á, í, ó, etc.) during search
hideDividersbooleantrueIf enabled, then search will consider item dividers and group titles and hide them if there are no found items right after them
hideGroupsbooleantrueIf enabled, then search will consider list view groups hide them if there are no found items inside of these groups
noShadowbooleanfalseDisable shadow rendering for MD theme
noHairlinebooleanfalseDisable 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

EventArgumentsDescription
<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. disableButtonText="Cancel"
  3. placeholder="Search in items"
  4. clearButton={true}
  5. ></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. <Searchbar
  2. disableButtonText="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>
  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. 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. );

← Range Slider

Sheet Modal →