Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@solid-primitives/autofocus
Advanced tools
Primitives for autofocusing HTML elements.
The native autofocus attribute only works on page load, which makes it incompatible with SolidJS. These primitives run on render, allowing autofocus on initial render as well as dynamically added components.
autofocus
- Directive to autofocus an element on render.createAutofocus
- Reactive primitive to autofocus an element on render.npm install @solid-primitives/autofocus
# or
yarn add @solid-primitives/autofocus
# or
pnpm add @solid-primitives/autofocus
autofocus
The autofocus
directive uses the native autofocus
attribute to determine it should focus the element or not.
Using this directive without autofocus={true}
(or the shorthand autofocus
) will not perform anything.
As a directive:
import { autofocus } from "@solid-primitives/autofocus";
// prevents from being tree-shaken by TS
autofocus
<button use:autofocus autofocus>
Autofocused
</button>;
// Autofocus directive can be disabled if `false` is passed as option
<button use:autofocus={false} autofocus>
Not Autofocused
</button>;
Or with ref
import { autofocus } from "@solid-primitives/autofocus";
<button ref={autofocus} autofocus>
Autofocused
</button>;
createAutofocus
createAutofocus
reactively autofocuses an element passid in as a signal.
import { createAutofocus } from "@solid-primitives/autofocus";
// Using ref
let ref!: HTMLButtonElement;
createAutofocus(() => ref);
<button ref={ref}>Autofocused</button>;
// Using ref signal
const [ref, setRef] = createSignal<HTMLButtonElement>();
createAutofocus(ref);
<button ref={setRef}>Autofocused</button>;
You may see the working example here: https://primitives.solidjs.community/playground/autofocus/
Source code: https://github.com/solidjs-community/solid-primitives/blob/main/packages/autofocus/dev/index.tsx
See CHANGELOG.md
FAQs
Primitives for autofocusing HTML elements
The npm package @solid-primitives/autofocus receives a total of 298 weekly downloads. As such, @solid-primitives/autofocus popularity was classified as not popular.
We found that @solid-primitives/autofocus demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.