Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
better-select
Advanced tools
Readme
A progressively enhanced, lightweight, customizable, and accessible <select>
custom element with text input.
A single file, weighing only 7KB (2.6KB gzip), and having no dependencies.
Based on Adam Silver's article Building an accessible auto-complete control, and some improvements of my own.
All you need to do is wrap your <select>
element inside a <better-select>
element, and the <select>
will be enhanced. If for some reason, your JavaScript fails to load (or until it loads), users will still be able to access a working <select>
menu. You don't need to change your forms input handling either.
<script src="./better-select.js" type="module"></script>
<better-select>
<select name="country" id="country">
<option value="">Select</option>
<option value="in">India</option>
<option value="au">Australia</option>
<option value="ja">Japan</option>
</select>
</better-select>
You can import better-select.js from CDNs like unpkg. The package is also available on npm.
<script type="module">
import BetterSelect from "./better-select.js";
customElements.define("my-better-select", BetterSelect);
</script>
The custom element can be styled using CSS custom properties. Following properties are presently available with along their default values:
/* input box */
--input-color: #000;
--input-background: #fff;
--input-border-width: 2px;
--input-border-color: #718096;
/* focused/active input box */
--focus-outline-width: 3px;
--focus-outline-color: #ecc94b;
/* options list wrapper */
--menu-max-height: 16em;
/* options */
--item-padding: 0.5em;
--item-color: #000;
--item-background: #fff;
--item-color-active: #fff;
--item-background-active: #111;
/* dropdown arrow */
--caret-color: var(--input-color);
Method 1: Extend isMatch
method of BetterSelect
class:
import BetterSelect from "./better-select.js";
class EventBetterSelect extends BetterSelect {
constructor() {
super();
}
/**
* @param {HTMLOptionElement} option an option from select element
* @param {string} value the value user has typed
* @returns {boolean} whether this option be listed or not
*/
isMatch(option, value) {
return option.getAttribute("data-value").startsWith(value);
}
}
customElements.define("my-better-select", BetterSelect);
Method 2: Add a globally available function name as an attribute to the element
<better-select match="myMatcherFunction">
<select name="country" id="country">
<option value="in">India</option>
<!-- … -->
</select>
</better-select>
<script>
function myMatcherFunction(option, value) {
return option.value.startsWith(value);
}
</script>
FAQs
A progressively enhanced, lightweight, customizable, and accessible <select> custom element with text input
The npm package better-select receives a total of 94 weekly downloads. As such, better-select popularity was classified as not popular.
We found that better-select demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.