Class CGSelect

Description

This class implements the functionality of a custom select, with customization capabilities.

Author

Ovsyanikov Maxim

Hierarchy

  • CGSelect

Implements

Constructors

  • Description

    The constructor takes an object and renders the select.

    Example

    options = {
    selector: 'Unique selector',
    selected: 'Selected item',
    placeholder: '...',
    lable: '...'
    items: [string|number|object],
    darkTheme: true/false,
    searchMode: true/false,
    closeOnSelect: true/false,
    nativeSelectMode: true/false,
    listDisplayMode: true/false,
    language: 'ru/en',
    styles: {
    head: {
    background: '...',
    },
    list: {...},
    chips: {...},
    caret: {...},
    placeholder: {...},
    lable: {..},
    },
    event: '...',
    url: 'http/...',
    multiselect: true/false,
    multiselectTag: true/false,
    }

    Parameters

    • setting: ICgSelect

      Object accepting select settings.

    Returns CGSelect

Properties

btnCntr?: null | Element

Button, to control the select.

caret: undefined | null | Element

Variable for carriage control.

category?: string

Transferred categories.

closeOnSelect?: boolean

An optional parameter that is responsible for the behavior of the select when opening, if closeOnSelect: false, then when an element is selected in the selector, closing does not occur, and you can select another element by default, closeOnSelect:true.

darkTheme?: boolean

An optional parameter that is responsible for enabling a light / dark theme by default, the dark theme is set (darkTheme == true).

element: null | Element

Created HTML element.

event?: string

An optional parameter that is responsible for the behavior of the select, passing to this parameter an event of the 'mouseenter' type, select will open on hover.

indexes: number[] = []

Array of indexes of selected elements.

items?: any

*Required parameter (if no other way to get data (url) is specified), this is an array of elements, which will be displayed in the select when selected.

lable?: string

An optional parameter that adds a lable before the select.

language?: string

Optional parameter responsible for the localization of some text elements.

list: null | Element

Created list(ul), with class list.

listDisplayMode?: boolean

An optional parameter that is responsible for the behavior of the select when opening.

multiselect?: boolean

An optional parameter, which is responsible for the behavior of the select, adds the ability to select multiple elements. Selected elements are rendered as plain text, separated by commas.

multiselectTag?: boolean

An optional parameter that is responsible for the behavior of the select, for him, *** works only in a place with a multiselect connection.

nativeSelectMode?: boolean

An optional parameter that is responsible for the behavior of the select when opened on mobile devices.

options: ICgSelect

Select settings passed when creating an instance of the class.

placeholder?: string

Placeholder optional parameter to which the text of the select placeholder is passed.

randomId: string

Unique Id for elements.

searchMode?: boolean

An optional parameter that adds a live search on the select elements.

selected?: string

An optional parameter, which is passed the element that will be selected initially in the select.

selectedItems: string | string[]

Selected or an array of selected items from a list.

selector?: string

Unique selector - *mandatory parameter (indicator) that is set when creating a select.

styles?: IStyle

An optional parameter that is responsible for customizing the select elements, objects with CSS properties for customizable elements are passed to it.

url?: string

Required parameter (if no other way to get data (items) is specified), data that comes from the backend in the format { id: "", title: "", value: ""}.

Accessors

  • get indexesOf(): number | number[]
  • Returns

    Returns the indices of the selected element(s) as an array / empty array.

    Description

    A getter that returns the indexes of the selected element(s) of the select.

    Returns number | number[]

  • get value(): string | string[]
  • Returns

    Returns the selected element(s) as an array / element / null.

    Description

    Getter returning the selected element(s) of the select.

    Returns string | string[]

Methods

  • Description

    adds the given element to the end of the list and redraws the list. Cannot be used when passing elements with categories.

    Method

    addItem

    Parameters

    • item: string | number | IItems

      added element.

    Returns undefined | false

  • Description

    a method that allows you to change the placeholder in the search and the text that is displayed if there is no result.

    Method

    addLanguage

    Parameters

    • language: ILanguage

      the object in which the fields for connecting the language are located has two mandatory fields placeholder, textInListSearch, selectPlaceholder.

    Returns void

  • Private

    Description

    A method that implements the selection of elements in different modes.

    Method

    addOptionsBehaviour

    Returns void

  • Description

    A method that allows you to open / close the select using buttons.

    Method

    buttonControl

    Parameters

    • button: Element

      HTML button.

    • method: string

      open/close method.

    Returns void

  • Private

    Method

    checkTheme

    Description

    Changes the color scheme from dark to light.

    Returns void

  • Private

    Description

    Closes the list.

    Method

    close

    Returns void

  • Private

    Description

    Closes the list on click outside of an element.

    Method

    closeSelectClick

    Returns void

  • Description

    removes the element by index from the list and redraws it. Cannot be used when passing elements with categories.

    Method

    deleteItem

    Parameters

    • index: number

      the index of the element to be removed.

    Returns void

  • Description

    removes all elements from the list and redraws it.

    Method

    deleteItemAll

    Returns void

  • Description

    A method that allows you to toggle the state of the disabled select.

    Method

    disabled

    Parameters

    • value: boolean

      Passed parameter to add the disabled attribute.

    Returns void

  • Private

    Description

    Changes the display of a sheet with a selection as a modal window.

    Method

    displayMode

    Parameters

    • listDisplayMode: boolean

      parameter responsible for displaying the selection in the form of a modal window.

    Returns void

  • Returns

    returns a reference to the selected HTML element.

    Method

    getElement

    Parameters

    • numberItem: number

      returned element number.

    Returns any

  • Private

    Private method for initializing an instance of the ICgSelect class.

    Method

    init

    Member

    Description

    Private method. General initialization of the select. Obtaining tinctures and converting select elements.

    Example

    {
    selector: '.cg-dropdown_one',
    placeholder: 'Choose a car',
    items: [
    'BMW',
    {
    id: '213sade',
    title: 'Opel',
    value: 1,
    },
    'Mersedes',
    'MAN',
    'max',
    ],
    darkTheme: true,
    multiselect: true,
    multiselectTag: true,
    }

    Parameters

    Returns void

  • Private

    Description

    Opens and closes the list by the passed event.

    Method

    initEvent

    Returns void

  • Private

    Method

    initSelected

    Description

    Renders and styles the select.

    Parameters

    • Optional select: string

      optional element. Used in the selectedIndex method.

    Returns void

  • Private

    Description

    Opens a list to select an element.

    Method

    open

    Parameters

    • Optional oneClick: boolean

      optional parameter passed from the buttonControl function.

    Returns void

  • Private

    Method

    render

    Description

    Render elements in select.

    Parameters

    • Optional select: string

      optional element. Passed to the initSelected.

    Returns void

  • Private

    Method

    renderUrl

    Description

    Rendering elements in the select passed from the URL and setting them up.

    Returns Promise<void>

  • Private

    Description

    The method that implements the search for elements in the select.

    Method

    searchMode

    Parameters

    • random: string

      unique value for input element.

    Returns void

  • Description

    selects the element that will be initially rendered in the select.

    Method

    selectIndex

    Parameters

    • index: number

      the index of the selected element.

    Returns void

  • Private

    Description

    Changes the display of the select on mobile devices.

    Method

    selectMode

    Parameters

    • nativeSelectMode: boolean

      parameter responsible for adding native select.

    Returns void

Generated using TypeDoc