Searchbar - 图1

Searchbar Svelte Component

Searchbar Svelte component represents Framework7’s Searchbar component.

Searchbar Components

There are following components included:

  • 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
<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 Svelte 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. />
  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 calling .instance() component’s method. For example:

  1. <Searchbar bind:this={component}>...</Searchbar>
  2. <script>
  3. let component;
  4. // to get instance in some method
  5. component.instance()
  6. </script>

Examples

Usual Searchbar

  1. <Page withSubnavbar>
  2. <Navbar title="Searchbar">
  3. <Subnavbar inner={false}>
  4. <Searchbar
  5. searchContainer=".search-list"
  6. searchIn=".item-title"
  7. disableButton={!theme.aurora}
  8. />
  9. </Subnavbar>
  10. </Navbar>
  11. <List class="searchbar-not-found">
  12. <ListItem title="Nothing found"></ListItem>
  13. </List>
  14. <List class="search-list searchbar-found">
  15. <ListItem title="Acura" />
  16. <ListItem title="Audi" />
  17. <ListItem title="BMW" />
  18. <ListItem title="Cadillac " />
  19. <ListItem title="Chevrolet " />
  20. <ListItem title="Chrysler " />
  21. <ListItem title="Dodge " />
  22. <ListItem title="Ferrari " />
  23. <ListItem title="Ford " />
  24. <ListItem title="GMC " />
  25. <ListItem title="Honda" />
  26. <ListItem title="Hummer" />
  27. <ListItem title="Hyundai" />
  28. <ListItem title="Infiniti " />
  29. <ListItem title="Isuzu " />
  30. <ListItem title="Jaguar " />
  31. <ListItem title="Jeep " />
  32. <ListItem title="Kia" />
  33. <ListItem title="Lamborghini " />
  34. <ListItem title="Land Rover" />
  35. <ListItem title="Lexus " />
  36. <ListItem title="Lincoln " />
  37. <ListItem title="Lotus " />
  38. <ListItem title="Mazda" />
  39. <ListItem title="Mercedes-Benz" />
  40. <ListItem title="Mercury " />
  41. <ListItem title="Mitsubishi" />
  42. <ListItem title="Nissan " />
  43. <ListItem title="Oldsmobile " />
  44. <ListItem title="Peugeot " />
  45. <ListItem title="Pontiac " />
  46. <ListItem title="Porsche" />
  47. <ListItem title="Regal" />
  48. <ListItem title="Saab " />
  49. <ListItem title="Saturn " />
  50. <ListItem title="Subaru " />
  51. <ListItem title="Suzuki " />
  52. <ListItem title="Toyota" />
  53. <ListItem title="Volkswagen" />
  54. <ListItem title="Volvo" />
  55. </List>
  56. </Page>
  57. <script>
  58. import {theme, Page, Navbar, Subnavbar, Searchbar, List, ListItem} from 'framework7-svelte';
  59. </script>

Expandable Searchbar

  1. <Page>
  2. <Navbar title="Searchbar">
  3. <NavRight>
  4. <Link searchbarEnable=".searchbar-demo" iconIos="f7:search" iconAurora="f7:search" iconMd="material:search"></Link>
  5. </NavRight>
  6. <Searchbar
  7. class="searchbar-demo"
  8. expandable
  9. searchContainer=".search-list"
  10. searchIn=".item-title"
  11. disableButton={!theme.aurora}
  12. />
  13. </Navbar>
  14. <List class="searchbar-not-found">
  15. <ListItem title="Nothing found"></ListItem>
  16. </List>
  17. <List class="search-list searchbar-found">
  18. <ListItem title="Acura" />
  19. <ListItem title="Audi" />
  20. <ListItem title="BMW" />
  21. <ListItem title="Cadillac " />
  22. <ListItem title="Chevrolet " />
  23. <ListItem title="Chrysler " />
  24. <ListItem title="Dodge " />
  25. <ListItem title="Ferrari " />
  26. <ListItem title="Ford " />
  27. <ListItem title="GMC " />
  28. <ListItem title="Honda" />
  29. <ListItem title="Hummer" />
  30. <ListItem title="Hyundai" />
  31. <ListItem title="Infiniti " />
  32. <ListItem title="Isuzu " />
  33. <ListItem title="Jaguar " />
  34. <ListItem title="Jeep " />
  35. <ListItem title="Kia" />
  36. <ListItem title="Lamborghini " />
  37. <ListItem title="Land Rover" />
  38. <ListItem title="Lexus " />
  39. <ListItem title="Lincoln " />
  40. <ListItem title="Lotus " />
  41. <ListItem title="Mazda" />
  42. <ListItem title="Mercedes-Benz" />
  43. <ListItem title="Mercury " />
  44. <ListItem title="Mitsubishi" />
  45. <ListItem title="Nissan " />
  46. <ListItem title="Oldsmobile " />
  47. <ListItem title="Peugeot " />
  48. <ListItem title="Pontiac " />
  49. <ListItem title="Porsche" />
  50. <ListItem title="Regal" />
  51. <ListItem title="Saab " />
  52. <ListItem title="Saturn " />
  53. <ListItem title="Subaru " />
  54. <ListItem title="Suzuki " />
  55. <ListItem title="Toyota" />
  56. <ListItem title="Volkswagen" />
  57. <ListItem title="Volvo" />
  58. </List>
  59. </Page>
  60. <script>
  61. import {theme, Page, Navbar, NavRight, Link, Subnavbar, Searchbar, List, ListItem} from 'framework7-svelte';
  62. </script>

← Range Slider

Sheet Modal →