An open API service indexing awesome lists of open source software.

https://github.com/navix/sx-focus-listener

🕸 Advanced focus listener for Angular.
https://github.com/navix/sx-focus-listener

angular focus-management multi-focus

Last synced: 2 months ago
JSON representation

🕸 Advanced focus listener for Angular.

Awesome Lists containing this project

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 ``).

## Installation

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

## Usage

### In templates

```html


Group focused: {{ group.focusListener.focused | json }}


In group!
In group!
In group!
Out of group


Manual registration in group.


Button in group!
Out of group

```

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