Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

select-pure

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

select-pure

Custom JavaScript <select> component. Easy-to-use, accessible, mobile friendly and super efficient

  • 2.0.0-alpha.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
604
increased by45.89%
Maintainers
1
Weekly downloads
 
Created
Source

Custom JavaScript <select> component. Easy-to-use, accessible, mobile friendly and super efficient.

npm version gzip size brotli size npm Build Status codecov

Description

SelectPure is a Web Component (Custom Element) which makes it super easy to use and customize. Main goal is to use extended API of the native HTML <select> element and provide additional features, like autocomplete, custom styling and many more. The package itself is stable to be used, however, if you've found any issues, please report them here or create a PR of your own.

If you want to use older version, please refer to this README.

Usage

SelectPure is very easy to use. At first you have to install a package

yarn add select-pure

or

npm i select-pure --save

then include it in your JavaScript file

import 'select-pure';

and use in the similar way as you would use a native HTML <select>.

<select-pure name="country" id="country">
  <option-pure value="" disabled hidden>-- Please select a country --</option-pure>
  <option-pure value="UA">Ukraine</option-pure>
  <option-pure value="PL">Poland</option-pure>
  <option-pure value="DE">Germany</option-pure>
  <option-pure value="US">USA</option-pure>
  <option-pure value="RU" disabled>Russia</option-pure>
</select-pure>

SelectPure instance

In order to call API methods of the SelectPure, subscribe to callbacks or use it's properties, you can simple use querySelector.

const selectPure = document.querySelector("select-pure");

console.log(selectPure.selectedIndex);

selectPure.disable();

Attributes

<select-pure> supports the following attributes: name, id and disabled.

<option-pure> supports value, label, disabled, selected and hidden attributes.

Available properties

propertydescription
selectedIndexReturns index of the selected option. You can also manipulate selected value with changing this property (selectPure.selectedIndex = 2). Just like in the native <select>.
valueReturns selected value.

Callbacks

If you want to set a callback for when the new value is selected, you can just use the traditional addEventListener.

const selectPure = document.querySelector("select-pure");
selectPure.addEventListener("change", (event) => {
  // You can use
  // event.target.value or
  // event.currentTarget.value
});

API methods

methoddescription
disable()Disables select.
enable()Enables select.
open()Opens a dropdown.
close()Closes a dropdown.

Custom styles

SelectPure offers high level of customisation. You can match any design you want by just providing a simple set of css variables. Below you can find their names and default values that are included in the package.

select-pure {
  --select-height: 44px;
  --select-width: 100%;
  --border-radius: 4px;
  --border-width: 1px;
  --border-color: #000;
  --padding: 0 10px;
  --dropdown-z-index: 2;
  --disabled-background-color: #bdc3c7;
  --disabled-color: #ecf0f1;
  --background-color: #fff;
  --color: #000;
  --hover-background-color: #e3e3e3;
  --hover-color: #000;
  --selected-background-color: #e3e3e3;
  --selected-color: #000;
  --dropdown-gap: 0;
  --font-size: 14px;
  --font-family: inherit;
  --font-weight: 400;
  --select-outline: 2px solid #e3e3e3;
}

<form> support

If you place <select-pure> inside a <form> and specify a name or id attribute, it will then append a hidden input with a given name inside a <form> and trigger change event, when value is selected.

TODO

2.1

  • Autocomplete input
  • Callback for autocomplete input
  • Custom matching/filter pattern
  • Fill README with React/Angular/Vue/Svelte/Purejs examples of usage;
  • Precommit hooks;
  • Add destroy method;
  • Make sure Select behaves correctly when attributes are changed or options are removed from the DOM (MutationObserver);
  • Sometimes one select scrolls dropdown in the others?
  • Don't close dropdown in multiple mode.
  • Use connectedCallback / disconnectedCallback to remove listeners when element is destroyed;

2.2

  • Option groups;
  • Required attribute support
  • Contribution guide;
  • Position of the dropdown;

License

MIT

Keywords

FAQs

Package last updated on 29 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc