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

Search

Extends:

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
    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

    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(): *

    Inherited Summary

    From class Component
    public static

    component(props: Object, children: *): Object

    Get a Mithril component object for this component, preloaded with props.

    public static

    initProps(props: Object)

    Initialize the component's props.

    public

    element: *

    The root DOM element for the component.

    public

    The properties passed into the component.

    public

    Whether or not to retain the component's subtree on redraw.

    public

    $(selector: String): jQuery

    Returns a jQuery object for this component's element. If you pass in a selector string, this method will return a jQuery object, using the current element as its buffer.

    For example, calling component.$('li') will return a jQuery object containing all of the li elements inside the DOM element of this component.

    public

    config(isInitialized: Boolean, context: Object, vdom: Object)

    Called after the component's root element is redrawn. This hook can be used to perform any actions on the DOM, both on the initial draw and any subsequent redraws. See Mithril's documentation for more information.

    public

    Called when the component is destroyed, i.e.

    public

    Get the renderable virtual DOM that represents the component's view.

    This should NOT be overridden by subclasses. Subclasses wishing to define their virtual DOM should override Component#view instead.

    protected

    init()

    Called when the component is constructed.

    protected

    Get the virtual DOM that represents the component's 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 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

    Called after the component's root element is redrawn. This hook can be used to perform any actions on the DOM, both on the initial draw and any subsequent redraws. See Mithril's documentation for more information.

    Override:

    Component#config

    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

    Called when the component is constructed.

    Override:

    Component#init

    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

    Get the virtual DOM that represents the component's view.

    Override:

    Component#view

    Return:

    *