https://github.com/geocine/avn-select
Styleable select custom element
https://github.com/geocine/avn-select
custom-elements dropdown select stenciljs webcomponents
Last synced: 4 months ago
JSON representation
Styleable select custom element
- Host: GitHub
- URL: https://github.com/geocine/avn-select
- Owner: geocine
- License: mit
- Created: 2018-07-27T14:08:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:16:46.000Z (almost 3 years ago)
- Last Synced: 2025-04-03T03:51:10.318Z (6 months ago)
- Topics: custom-elements, dropdown, select, stenciljs, webcomponents
- Language: TypeScript
- Size: 772 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Select Component
This a styleable select Web Component built using Stencil.
## Usage
Populating the options
```html
const avnSelect = document.querySelector('#sample');
avnSelect.options = [
{
"label": "Orange",
"value": "OR"
},
{
"label": "Apple",
"value": "APP"
}
];
```OR you can initialize it declaratively
```html
Orange
Apple
```> NOTE: this is only for initialization, for updating you need to modify the `.options` attribute in an immutable way eg:
```js
const avnSelect = document.querySelector('#sample');
avnSelect.options = [...avnSelect.options, {label: 'Strawberry', value: 'STR'}];
```Listening for `change` event
```js
const avnSelect = document.querySelector('#sample');
avnSelect.addEventListener('change', (option) => {
// returns { label , value }
// do something with returned value
})
```Getting the selected value
```js
const avnSelect = document.querySelector('#sample');
const selectedValue = avnSelect.value;
// returns { label, value }
```## Styling
These are the available CSS variables and their default values:
```css
:host {
--arrow-color: #000;
--arrow-bg-color: #fff;
--border-color: #ccc;
--selected-color: #0A3874;
--hover-color: #1668d3;
--hover-text-color: #fff;
--height: 34px;
--border-radius: 5px;
--content-width: 100%;
--content-border-radius: 0;
--focused-border-color: rgba(8,57,114,0.5);
--focused-border-shadow: inset 0 1px 1px;
}
```