An open API service indexing awesome lists of open source software.

https://github.com/samdutton/multi-input

Custom input element to select multiple items using a datalist to suggest options.
https://github.com/samdutton/multi-input

Last synced: about 1 month ago
JSON representation

Custom input element to select multiple items using a datalist to suggest options.

Awesome Lists containing this project

README

          

# <multi-input>

multi-input custom element showing selection of multiple Shakespeare characters

Custom element for selecting multiple items using an `input` and `datalist` to suggest options.

Delete items with Backspace or by tapping/clicking an item's × icon.


| [View and remix this project live on Glitch](https://glitch.com/~multi-input) |
| --- |


## Usage

1. Add [multi-input.js](https://github.com/samdutton/multi-input/blob/glitch/multi-input.js) to your project and link to it:

```html

```

2. Wrap an `input` and a `datalist` in a `` (see [index.html](https://github.com/samdutton/multi-input/blob/glitch/index.html#L14)):

```html





...


```

3. Get selected values like this (see [script.js](https://github.com/samdutton/multi-input/blob/glitch/script.js)):

```js
const getButton = document.getElementById('get');
const multiInput = document.querySelector('multi-input');
getButton.onclick = () => {
console.log(multiInput.getValues());
}
```

## Can I style the components?

Sure.

There are several custom properties:

```
--multi-input-border
--multi-input-item-bg-color
--multi-input-item-border
--multi-input-item-font-size
--multi-input-input-font-size
```

Style components like this:

``` css
multi-input {
--multi-input-border: 2px solid red;
}
```

## Known issues

### Problems with shadow DOM CSS pseudo classes

Two selectors have been added outside the shadow DOM using a `multi-input` selector:

* `::slotted(input)::-webkit-calendar-picker-indicator` doesn't work in any browser.
* `::slotted(div.item)::after` doesn't work in Safari.


## My platform doesn't support custom elements :^|

Custom elements are [widely supported by modern browsers](https://caniuse.com/#search=custom%20elements).

However, `` simply wraps an `input` element that has a `datalist`, so behaviour will degrade gracefully to a 'normal' `datalist` experience in browsers without custom element support.




## My platform doesn't support datalist :^| :^|

The `datalist` element is [supported by all modern browsers](https://caniuse.com/#feat=datalist).

If your target browser doesn't support `datalist`, behaviour will fall back to the plain old `input` experience.


## Obligatory screencast

Screencast showing Shakespeare character names being selected via a multi-input custom element