GithubHelp home page GithubHelp logo

hhy5277 / multiselect-web-component Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tabalinas/multiselect-web-component

0.0 1.0 0.0 260 KB

Multiselect Web Component in VanillaJS

Home Page: http://tabalinas.github.io/multiselect-web-component

HTML 100.00%

multiselect-web-component's Introduction

Multiselect Web Component

A multiselect widget created using Web Components.

multiselect web component

Demo

Multiselect Demo

Usage

Import multiselect.html and use <x-multiselect> element. Define items with <li> elements. To make an item selected add selected attribute.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="import" href="multiselect.html">
</head>
<body>
    <x-multiselect placeholder="Select Value">
        <li value="1" selected>Item 1</li>
        <li value="2">Item 2</li>
        <li value="3" selected>Item 3</li>
        <li value="4">Item 4</li>
    </x-multiselect>
</body>
</html>

API

Attribute placeholder

Add attribure placeholder to set multiselect placeholder (text to be displayed when no items are selected).

    <x-multiselect placeholder="Multiselect Placeholder">
    ...
    </x-multiselect>

Method selectedItems()

Returns selected item values as an Array.

// returns an array of values, e.g. [1, 3]
var selectedItems = multiselect.selectedItems();

Event change

Is fired each time selected items are changes.

multiselect.addEventListener('change', function() {
    // print selected items to console
    console.log('Selected items:', this.selectedItems());
});

Browser Support

Browser support is limited by support of Web Components.

Add webcomponentjs polyfill to be able to use the component in all modern browsers.

multiselect-web-component's People

Contributors

fomkin avatar santuccir-upmc avatar tabalinas 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.