Socket
Socket
Sign inDemoInstall

ts-select2

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ts-select2

TsSelect2 is a version of Select2 written in typescript without any dependencies. It supports searching, remote data sets, and infinite scrolling of results.


Version published
Weekly downloads
277
increased by52.2%
Maintainers
1
Install size
1.02 MB
Created
Weekly downloads
 

Readme

Source

Description

TsSelect2 is a version of Select2 written in typescript without any dependencies. It supports searching, remote data sets, and infinite scrolling of results. Use the TsSelect2 library for development only, not production for now.

Installation - NPM

npm i ts-select2

Installation - Browser

<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://unpkg.com/ts-select2@0.2.3/dist/ts-select2.min.js"></script>

Usage

Add the following libraries to the page:

  • ts-select2.min.js

Add the following stylesheets from Select2 to the page:

  • select2.min.css

Initialisation

<select data-placeholder="Select something" multiple="multiple" class="form-control select-access-multiple-enable">
    <option value="AK">Alaska</option>
    <option value="CA">California</option>
    <option value="AZ" selected>Arizona</option>
    <option value="CO">Colorado</option>
    <option value="ID">Idaho</option>
    <option value="WY" selected>Wyoming</option>
    <option value="CT">Connecticut</option>
</select>

Example

To initialise the select, call TsSelect2 on the element:

const select2 = new TsSelect2(select, {minimumResultsForSearch: Infinity, width: `250px`});

/**
 * Opens the select
 */
select2.open();

/**
 * Closes the select.
 */
select2.close();

/**
 * Toggles the dropdown
 */
select2.toggleDropdown();

/**
 * Gets if the dropdown is enabled
 */
select2.isEnabled();

/**
 * Gets if the dropdown is disabled
 */
select2.isDisabled();

/**
 * Gets if the dropdown is opened
 */
select2.isOpen();

/**
 * Gets if the dropdown is focused
 */
select2.focus();

/**
 * Returns an array of data
 */
select2.data();

/**
 * Destroy the select.
 */
select2.destroy();

/**
 * Use one of the arguments: 'open', 'close', 'destroy'
 */
select2.select2('open');

Keywords

FAQs

Last updated on 11 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc