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

Search

Extends:

flarum/Component~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 current controller implements a searching method that returns a truthy value. If this is the case, an 'x' button will be shown next to the search field, and clicking it will call the clearSearch method on the controller.

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

    A list of queries that have been searched for.

    public

    An array of SearchSources.

    public

    The value of the search input.

    Method Summary

    Public Methods
    public

    clear()

    Clear the search input and the current controller's active search.

    public

    config(isInitialized: *)

    public

    Get the position of the currently selected search result item.

    public

    Get the active search in the app's current controller.

    public

    getItem(index: String): DOMElement

    Get the

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

    init()

    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 searched: Array source

    A list of queries that have been searched for.

    public sources: SearchSource[] source

    An array of SearchSources.

    public value: Function source

    The value of the search input.

    Public Methods

    public clear() source

    Clear the search input and the current controller's active search.

    public config(isInitialized: *) source

    Params:

    NameTypeAttributeDescription
    isInitialized *

    public getCurrentNumericIndex(): Integer source

    Get the position of the currently selected search result item.

    Return:

    Integer

    public getCurrentSearch(): String source

    Get the active search in the app's current controller.

    Return:

    String

    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 init() source

    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:

    *