Searchbar React Component

Searchbar React 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
spellcheckbooleanSets spellcheck attribute on input element
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:

<Searchbar
  disableButtonText="Cancel"
  placeholder="Search in items"
  clearButton={true}
></Searchbar>

{/* Renders to: */}

<form class="searchbar">
  <div class="searchbar-inner">
    <div class="searchbar-input-wrap">
      <input type="search" placeholder="Search">
      <i class="searchbar-icon"></i>
      <span class="input-clear-button"></span>
    </div>
    <span class="searchbar-disable-button">Cancel</span>
  </div>
</form>

With Slots:

<Searchbar
  disableButtonText="Cancel"
  placeholder="Search in items"
  clearButton={true}
>
  <div slot="inner-start">Inner Start</div>
  <div slot="inner-end">Inner End</div>
  <div slot="input-wrap-start">Input Wrap Start</div>
  <div slot="input-wrap-end">Input Wrap End</div>
  <div slot="before-inner">Before Inner</div>
  <div slot="after-inner">After Inner</div>
</Searchbar>

{/* Renders to: */}

<form class="searchbar">
  <div slot="before-inner">Before Inner</div>
  <div class="searchbar-inner">
    <div slot="inner-start">Inner Start</div>
    <div class="searchbar-input-wrap">
      <div slot="input-wrap-start">Input Wrap Start</div>
      <input type="search" placeholder="Search">
      <i class="searchbar-icon"></i>
      <span class="input-clear-button"></span>
      <div slot="input-wrap-end">Input Wrap End</div>
    </div>
    <span class="searchbar-disable-button">Cancel</span>
    <div slot="inner-end">Inner End</div>
  </div>
  <div slot="after-inner">After Inner</div>
</form>

Examples

Usual Searchbar

import React from 'react';
import {
  Page,
  Navbar,
  Subnavbar,
  Searchbar,
  List,
  ListItem,
  theme,
} from 'framework7-react';

export default () => (
  
    
  <Page>
    <Navbar title="Searchbar">
      <Subnavbar inner={false}>
        <Searchbar
          searchContainer=".search-list"
          searchIn=".item-title"
          disableButton={!theme.aurora}
        ></Searchbar>
      </Subnavbar>
    </Navbar>
    <List className="searchbar-not-found">
      <ListItem title="Nothing found"></ListItem>
    </List>
    <List className="search-list searchbar-found">
      <ListItem title="Acura"></ListItem>
      <ListItem title="Audi"></ListItem>
      <ListItem title="BMW"></ListItem>
      <ListItem title="Cadillac "></ListItem>
      <ListItem title="Chevrolet "></ListItem>
      <ListItem title="Chrysler "></ListItem>
      <ListItem title="Dodge "></ListItem>
      <ListItem title="Ferrari "></ListItem>
      <ListItem title="Ford "></ListItem>
      <ListItem title="GMC "></ListItem>
      <ListItem title="Honda"></ListItem>
      <ListItem title="Hummer"></ListItem>
      <ListItem title="Hyundai"></ListItem>
      <ListItem title="Infiniti "></ListItem>
      <ListItem title="Isuzu "></ListItem>
      <ListItem title="Jaguar "></ListItem>
      <ListItem title="Jeep "></ListItem>
      <ListItem title="Kia"></ListItem>
      <ListItem title="Lamborghini "></ListItem>
      <ListItem title="Land Rover"></ListItem>
      <ListItem title="Lexus "></ListItem>
      <ListItem title="Lincoln "></ListItem>
      <ListItem title="Lotus "></ListItem>
      <ListItem title="Mazda"></ListItem>
      <ListItem title="Mercedes-Benz"></ListItem>
      <ListItem title="Mercury "></ListItem>
      <ListItem title="Mitsubishi"></ListItem>
      <ListItem title="Nissan "></ListItem>
      <ListItem title="Oldsmobile "></ListItem>
      <ListItem title="Peugeot "></ListItem>
      <ListItem title="Pontiac "></ListItem>
      <ListItem title="Porsche"></ListItem>
      <ListItem title="Regal"></ListItem>
      <ListItem title="Saab "></ListItem>
      <ListItem title="Saturn "></ListItem>
      <ListItem title="Subaru "></ListItem>
      <ListItem title="Suzuki "></ListItem>
      <ListItem title="Toyota"></ListItem>
      <ListItem title="Volkswagen"></ListItem>
      <ListItem title="Volvo"></ListItem>
    </List>
  </Page>
    
  
);

Expandable Searchbar

import React from 'react';
import {
  Page,
  Navbar,
  NavRight,
  Link,
  Searchbar,
  List,
  ListItem,
  theme,
} from 'framework7-react';

export default () => (
  
    
  <Page>
    <Navbar title="Searchbar">
      <NavRight>
        <Link
          searchbarEnable=".searchbar-demo"
          iconIos="f7:search"
          iconAurora="f7:search"
          iconMd="material:search"
        ></Link>
      </NavRight>
      <Searchbar
        className="searchbar-demo"
        expandable
        searchContainer=".search-list"
        searchIn=".item-title"
        disableButton={!theme.aurora}
      ></Searchbar>
    </Navbar>
    <List className="searchbar-not-found">
      <ListItem title="Nothing found"></ListItem>
    </List>
    <List className="search-list searchbar-found">
      <ListItem title="Acura"></ListItem>
      <ListItem title="Audi"></ListItem>
      <ListItem title="BMW"></ListItem>
      <ListItem title="Cadillac "></ListItem>
      <ListItem title="Chevrolet "></ListItem>
      <ListItem title="Chrysler "></ListItem>
      <ListItem title="Dodge "></ListItem>
      <ListItem title="Ferrari "></ListItem>
      <ListItem title="Ford "></ListItem>
      <ListItem title="GMC "></ListItem>
      <ListItem title="Honda"></ListItem>
      <ListItem title="Hummer"></ListItem>
      <ListItem title="Hyundai"></ListItem>
      <ListItem title="Infiniti "></ListItem>
      <ListItem title="Isuzu "></ListItem>
      <ListItem title="Jaguar "></ListItem>
      <ListItem title="Jeep "></ListItem>
      <ListItem title="Kia"></ListItem>
      <ListItem title="Lamborghini "></ListItem>
      <ListItem title="Land Rover"></ListItem>
      <ListItem title="Lexus "></ListItem>
      <ListItem title="Lincoln "></ListItem>
      <ListItem title="Lotus "></ListItem>
      <ListItem title="Mazda"></ListItem>
      <ListItem title="Mercedes-Benz"></ListItem>
      <ListItem title="Mercury "></ListItem>
      <ListItem title="Mitsubishi"></ListItem>
      <ListItem title="Nissan "></ListItem>
      <ListItem title="Oldsmobile "></ListItem>
      <ListItem title="Peugeot "></ListItem>
      <ListItem title="Pontiac "></ListItem>
      <ListItem title="Porsche"></ListItem>
      <ListItem title="Regal"></ListItem>
      <ListItem title="Saab "></ListItem>
      <ListItem title="Saturn "></ListItem>
      <ListItem title="Subaru "></ListItem>
      <ListItem title="Suzuki "></ListItem>
      <ListItem title="Toyota"></ListItem>
      <ListItem title="Volkswagen"></ListItem>
      <ListItem title="Volvo"></ListItem>
    </List>
  </Page>
    
  
);