npm.io
0.0.5 • Published 3 years ago

@apsc/focus-action

Licence
MIT
Version
0.0.5
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
3

Action to control focusin and focusout for Svelte directive use

  • no dependencies
  • based on focusin and focusout events.
  • correctly detects loss of focus with tab key

Docs & Demo

Install

NPM
npm i -D @apsc/focus-action
PNPM
pnpm add -D @apsc/focus-action

API

let focused = false;
const focusFns = [() => (focused = true), () => (focused = false)];

<div class:focused use:useFocus={focusFns}>
  ...
</div>;

Based on focusin and focusout events.

Executes callbacks when the node or its children gain or lose focus.

Ensure the node or its children can be focused

Keywords