Code Monkey home page Code Monkey logo

ts-select2's Introduction

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/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://unpkg.com/[email protected]/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>

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');

ts-select2's People

Contributors

ivkan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.