Reference Source
import Search from 'flarum/components/Search'
public class | source

Search

Extends:

src/common/Component.js~Component → Search

The Search component displays a menu of as-you-type results from a variety of sources.

The search box will be 'activated' if the app's search state's getInitialSearch() value is a truthy value. If this is the case, an 'x' button will be shown next to the search field, and clicking it will clear the search.

ATTRS:

  • state: SearchState instance.

Member Summary

Public Members
public

Whether or not the search input has focus.

public

index: String | Integer

The index of the currently-selected

  • in the results list.
  • public

    loadingSources: Integer

    The number of sources that are still loading results.

    public
    public

    An array of SearchSources.

    public

    state: *

    Method Summary

    Public Methods
    public

    clear()

    Clear the search

    public

    Get the position of the currently selected search result item.

    public

    getItem(index: String): DOMElement

    Get the

  • in the search results with the given index (numeric or named).
  • public

    oncreate(vnode: *)

    public

    oninit(vnode: *)

    public
    public

    Navigate to the currently selected search result and close the list.

    public

    selectableItems(): jQuery

    Get all of the search result items that are selectable.

    public

    setIndex(index: Integer, scrollToItem: Boolean)

    Set the currently-selected search result item to the one with the given index.

    public

    Build an item list of SearchSources.

    public

    view(): *

    Public Members

    public hasFocus: Boolean source

    Whether or not the search input has focus.

    public index: String | Integer source

    The index of the currently-selected

  • in the results list. This can be a unique string (to account for the fact that an item's position may jump around as new results load), but otherwise it will be numeric (the sequential position within the list).
  • public loadingSources: Integer source

    The number of sources that are still loading results.

    public navigator: * source

    public sources: SearchSource[] source

    An array of SearchSources.

    public state: * source

    Public Methods

    public clear() source

    Clear the search

    public getCurrentNumericIndex(): Integer source

    Get the position of the currently selected search result item.

    Return:

    Integer

    public getItem(index: String): DOMElement source

    Get the

  • in the search results with the given index (numeric or named).
  • Params:

    NameTypeAttributeDescription
    index String

    Return:

    DOMElement

    public oncreate(vnode: *) source

    Params:

    NameTypeAttributeDescription
    vnode *

    public oninit(vnode: *) source

    Params:

    NameTypeAttributeDescription
    vnode *

    public onupdate() source

    public selectResult() source

    Navigate to the currently selected search result and close the list.

    public selectableItems(): jQuery source

    Get all of the search result items that are selectable.

    Return:

    jQuery

    public setIndex(index: Integer, scrollToItem: Boolean) source

    Set the currently-selected search result item to the one with the given index.

    Params:

    NameTypeAttributeDescription
    index Integer
    scrollToItem Boolean

    Whether or not to scroll the dropdown so that the item is in view.

    public sourceItems(): ItemList source

    Build an item list of SearchSources.

    Return:

    ItemList

    public view(): * source

    Return:

    *