Compatible select web component which works with any framework or no framework. This component is created using stencilJs
Demo link - https://select-component.netlify.app/
- Single Select
- Multi-select
- Accessiblitiy
- Clear options
- Select/Deselect options
For Single select in react,
let [singleSelectValue, setSingleSelectValue] = useState('football');
return (
<select-web
value={singleSelectValue}
onChange={(e) => setSingleSelectValue(e.target.value)}
>
<select-web-option value="football">Footbal</select-web-option>
<select-web-option value="cricket">Cricket</select-web-option>
<select-web-option value="duster">Duster</select-web-option>
<select-web-option value="basket">Basket</select-web-option>
</select-web>
)
For Multi select in react,
- Pass multipe=true attribute to the select-web component
- As HTML does not allow to pass array as attribute, strigify the array and then pass in value attribute as below
let [multiSelectValue, setMultiSelectValue] = useState(['football']);
return (
<select-web
multiple
value={JSON.stringify(multiSelectValue)}
onChange={(e) => setMultiSelectValue([...e.target.value])}
>
<select-web-option value="football">Footbal</select-web-option>
<select-web-option value="cricket">Cricket</select-web-option>
<select-web-option value="duster">Duster</select-web-option>
<select-web-option value="basket">Basket</select-web-option>
</select-web>
)
space/enter: toggles the dropdownup,down: navigates up and down the dropdown itemsenter: to select/deselect the dropdown item
Clone the project
git clone https://github.com/prashanthsasidharan/select-web-component.gitGo to the project directory
cd select-web-componentInstall component dependencies
cd component, yarnComponent server runs at http://localhost:3000/
Yarn startInstall Ember-demo dependencies
cd ember-demo, yarnEmber-demo server runs at http://localhost:3001/
yarn startInstall React-demo dependencies
cd react-select-demo, yarnReact-demo server runs at http://localhost:3002/
yarn startInstall Plain-js-demo dependencies
cd plain-demoPlain-js-demo server runs at http://localhost:3003/
yarn startView the app using http://localhost:3000/ in browser tab
Component: Stencil js
Demos: Ember, React, Vanilla js
Contributions are always welcome!