New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@solid-primitives/autofocus

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/autofocus

Primitives for autofocusing HTML elements

  • 0.0.111
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
316
decreased by-1.25%
Maintainers
3
Weekly downloads
 
Created
Source

Solid Primitives Autofocus

@solid-primitives/autofocus

turborepo size version stage

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.

Installation

npm install @solid-primitives/autofocus
# or
yarn add @solid-primitives/autofocus
# or
pnpm add @solid-primitives/autofocus

autofocus

How to use it

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>;

Demo

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

Changelog

See CHANGELOG.md

Keywords

FAQs

Package last updated on 05 Mar 2024

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