Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
JS library that adds empty/dirty/touched CSS hooks to input and textarea elements
HookahJS is a tiny JavaScript library that monitors all input and textarea elements on your page and adds empty/dirty/touched
CSS hooks to each element automatically.
HookahJS is a tiny JavaScript library that monitors all input and textarea elements on your page and adds the following CSS classes in response to user interactions with each element:
hkjs--empty
- control element is emptyhkjs--not-empty
- control element is not emptyhkjs--pristine
- control element has not seen an input
or change
eventhkjs--dirty
- control element has seen an input
or change
eventhkjs--untouched
- control element has not seen a blur
eventhkjs--touched
- control element has seen a blur
eventHookahJS uses CSS @keyframes to detect new DOM elements so once the library is loaded, it will automatically add CSS hooks to new input and textarea elements. HookahJS is 1056 bytes (minified + gzipped).
To use HookahJS you only need to add hookah.js
to your page and the library will automatically add event listeners to all current and future input and textarea elements. The following example will draw a red box around an invalid input box after the user has touched the element:
<!doctype html>
<html>
<head>
<script src="//cdn.rawgit.com/muicss/hookahjs/0.0.6/dist/hookah.min.js"></script>
<style>
.hkjs--touched:not(:valid) {
border: 1px solid red;
}
</style>
</head>
<body>
<input type="text" required>
<input type="email" required>
</body>
</html>
HookahJS uses CSS @keyframes to detect new DOM elements so once the library is loaded, it will automatically add CSS hooks to new input and textarea elements.
Note: HookahJS uses CSS @keyframes to detect new DOM elements automatically. To use HookahJS in IE9 you can initialize DOM elements explicitly with hkjs.init()
.
For production systems we recommend that you host the library file yourself which you can download from the dist/
directory in this repository:
For tighter integration with your code you can also use the HookahJS NPM package:
$ npm install --save hookahjs
var hkjs = require('hookahjs');
document.addEventListener('DOMContentLoaded', function() {
hkjs.init();
});
HookahJS can be loaded asynchronously but keep in mind that if HookahJS is initialized after the DOM content has been displayed to the user, there may be a flash of unstyled content. To avoid this you can seed your page with .hkjs--empty
/.hkjs--not-empty
classes as necessary.
By default, HookahJS will add event listeners to all current and future input and textarea elements. To prevent this behavior you can listen to the hkjs-init
event and call the preventDefault()
method on the event object. You can also use the hkjs
global object to add hooks to individual elements:
window.addEventListener('hkjs-init', function(ev) {
// prevent HookahJS from adding hooks to all <input> and <textarea> elements
ev.preventDefault();
// use the `hkjs` global object to add hooks to elements manually
var inputEl = document.getElementById('my-input-element');
hkjs.init(inputEl);
});
HookahJS can detect all change
and input
events triggered by user interactions but it can't detect programmatic changes to control elements. To update the HookahJS CSS classes after making a programmatic change to a control element, you can trigger a change
or input
event on the element:
// modify element
var inputEl = document.getElementById('my-input-element');
inputEl.value = 'Programmatic input';
// initialize event object (with bubbles = false)
var ev = document.createEvent('HTMLEvents');
ev.initEvent('change', false);
// trigger event
inputEl.dispatchEvent(ev);
FAQs
JS library that adds empty/dirty/touched CSS hooks to input and textarea elements
The npm package hookahjs receives a total of 79 weekly downloads. As such, hookahjs popularity was classified as not popular.
We found that hookahjs 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.