# @oleksa/sx-focus-listener

> [![npm version](https://badge.fury.io/js/%40oleksa%2Fsx-focus-listener.svg)](https://www.npmjs.com/@oleksa/sx-focus-listener)

Latest version **10.0.0** (published 2020-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @oleksa/sx-focus-listener
pnpm add @oleksa/sx-focus-listener
yarn add @oleksa/sx-focus-listener
bun add @oleksa/sx-focus-listener
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 10.0.0 |
| Published | 2020-09-02 |
| First published | 2020-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 78.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Oleksa Novyk |
| Maintainers | oleksa |

## Links

- npm: https://www.npmjs.com/package/@oleksa/sx-focus-listener
- Repository: https://github.com/navix/sx-focus-listener
- Homepage: https://github.com/navix/sx-focus-listener#readme
- Issues: https://github.com/navix/sx-focus-listener/issues
- npm.io page: https://npm.io/package/@oleksa/sx-focus-listener

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.0.0

## Recent versions

- 10.0.0 (latest) — 2020-09-02
- 10.0.0-beta.2 (beta) — 2020-08-29
- 10.0.0-beta.1 — 2020-08-29

## README

[![npm version](https://badge.fury.io/js/%40oleksa%2Fsx-focus-listener.svg)](https://www.npmjs.com/@oleksa/sx-focus-listener)

# sx-focus-listener

### 🕸 Advanced focus listener for Angular

Register element in the service and use focus/blur observables.

The service handles focus/blur for one or a group of elements.

If focus moves among elements in a defined group, blur event will not be fired.

Be aware, click on non-focusable elements will cause blur event (focus switch to `<body>`).


## Installation

```
$ npm i @oleksa/sx-focus-listener
```


## Usage

### In templates

```html
<div #group="sxFocusGroup" sxFocusGroup>
  <h4>Group focused: {{ group.focusListener.focused | json }}</h4>
  <button sxFocusEl>In group!</button>
  <button sxFocusEl>In group!</button>
  <button sxFocusEl>In group!</button>
  <button>Out of group</button>
</div>
<div>
  <h4>Manual registration in group.</h4>
  <button [focusListener]="group.focusListener" sxFocusEl>Button in group!</button>
  <button>Out of group</button>
</div>
```

### As a service

```typescript
...
@Component({
  ...
  providers: [SxFocusListener],
})
export class MyComponent {
  constructor(
    private focusListener: SxFocusListener,
    ...
  ) {
  }
  
  ...

  this.focusListener.add(nativeElement1);
  this.focusListener.add(nativeElement2);
  this.focusListener.add(nativeElement3);
  this.focusListener.focus.subscribe((event: any) => {});
  this.focusListener.blur.subscribe((event: any) => {});
```


## License

MIT

---
_Source: https://npm.io/package/@oleksa/sx-focus-listener · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
