keep-parent-focused
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

keep-parent-focused

Build Status Coverage Status

Alternative to focus-within and inspired by css-tricks.

Getting started

npm install keep-parent-focused

Usage

keepParentFocused(element[, focusClass])

Parameters:

  • element <HTMLElement | null>: Any HTML element where the focusClass should get applied on. It will check all focusable children.
  • focusClass <String> (optional): String will get applied as class to given element. Default: focused

Returns:

  • Function: A function which can be called to remove all eventlisteners

Example:

import keepParentFocused from 'keep-parent-focused';

keepParentFocused(document.getElementById('my-element'));

// Applies '.focused' on '#my-element' when the button is focused
//
// <div id="my-element">
//   <button>Any button</button>
// <div>

Package Sidebar

Install

npm i keep-parent-focused

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

11.7 kB

Total Files

10

Last publish

Collaborators

  • jpeer