npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-focus-control

v5.1.0

Published

Library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility.

Downloads

403

Readme

npm version CircleCI Coverage Status GitHub issues npm bundle size NPM demo stack blitz Gitter

ngc focus control logo

Ngx Focus Control

Angular library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility.

Version compatibility

| Angular version | Ngx focus control version | |-----------------|---------------------------| | 8 - 13 | 0.0.0 - 3.x.x | | 14 | 4.x.x | | 15 | 5.x.x |

Instalation

npm install ngx-focus-control --save

then add NgxFocusControlModule into module imports

import {NgxFocusControlModule} from 'ngx-focus-control';

@NgModule({
// ...
  imports: [
    // ...
    NgxFocusControlModule,
    // ...
  ],
// ...
})

Usage

See DEMO app for usage.

Directives

  • Focus auto directive

auto-focuses element when an element is created, a page is visited, or delay data bidding is changed. Users can define delay of focus. 0 is the default delay when a delay is not specified.

<input placeholder="Input" class="input" [fuAuto]="500">
  • Focus control directive

allows the user to manually define the next and/or previous focus target.

<input placeholder="Input 1" class="input" id="input-1" [fuControl]="{next: '#input-3', previous: input2}">
<input #input2 placeholder="Input 2" class="input" id="input-2" [fuControl]="{next: '#input-1', previous: '#input-3'}">
<input placeholder="Input 3" class="input" id="input-3" [fuControl]="{next: input2, previous: '#input-1'}">
  • Focus selector directive

allows the user to manually define the next and previous focus target by the given query selector.

<input placeholder="Input 1" class="input focus-selector-item" [fuSelector]="'.focus-selector-item'">
<input placeholder="Input 2" class="input">
<input placeholder="Input 3" class="input focus-selector-item" [fuSelector]="'.focus-selector-item'">
  • Focus group directive

allows merging focusable elements into the group. The user focuses the whole group and can enter into this group by Enter press and leave the group by Escape press.

<div tabindex="0" id="group-1" class="box focus-selector-parent" [fuGroup]="{selector: '.focus-group-item'}">
  <div class="subtitle has-text-black">Group</div>
  <input type="text" tabindex="-1" placeholder="Input 1" class="input focus-group-item" id="input-1">
  <input type="text" tabindex="-1" placeholder="Input 2" class="input focus-group-item" id="input-2">
</div>
  • Focus lock directive

locks some area (div, span...). The first and last focusable child of the directive element are connected together (the next focus target of the last child is the first child and vice versa), useful for accessible modals.

<div id="lock-1" class="box focus-selector-parent" fuLock>
  <input type="text" placeholder="Input 1" class="input" id="input-1">
  <input type="text" placeholder="Input 2" class="input" id="input-2">
  <input type="text" placeholder="Input 3" class="input" id="input-3">
</div>
  • Focus if directive

focuses the element when condition bidding changes to True or blurs the element when condition bidding changes to False. Instead of primitive value, you can also pass observable, which focuses element when observable emits True and blur element when observable emits False.

<input type="text" placeholder="Input 16" class="input" id="input-16" [fuIf]="condition">
<input type="text" placeholder="Input 17" class="input" id="input-17" [fuIf]="observable$">
  • Focus switch directives

on parent element with some variable focuses child element with the value provided in focus case directive that matches. It matches the first element from top to bottom. If there is no match and you use the focus default directive, the element with this directive is focused. Value needs to change, to focus the element (if the switch variable has got value 0, and you set the variable again to 0, the element will not be focused). You can also pass observable into focus switch directive (works similar as in focus if directive).

<ng-container [fuSwitch]="switchValue">
  <input type="text" placeholder="Input 1" class="input" id="input-1" [fuCase]="'option-1'">
  <input type="text" placeholder="Input 2" class="input" id="input-2" [fuCase]="'option-2'">
  <input type="text" placeholder="Input 3" class="input" id="input-3" [fuCase]="'option-3'">
  <input type="text" placeholder="Input 4 Default" class="input" id="input-4" fuDefault>
</ng-container>
<button class="button is-success" (click)="switchValue = 'option-1'">Focus Input 1</button>
<button class="button is-success" (click)="switchValue = 'option-2'">Focus Input 2</button>
<button class="button is-success" (click)="switchValue = 'option-3'">Focus Input 3</button>
<button class="button is-success" (click)="switchValue = 'option-100'">Switch to non-existing value</button>
  • Focus history directive

stores focused elements into history and thanks to history service FocusHistoryService you can go back in focus history using focusHistoryService.focusPrevious().

<input type="text" placeholder="Input 1" class="input" id="input-1" fuHistory>
<input type="text" placeholder="Input 2" class="input" id="input-2" fuHistory>
<button class="button is-info" (click)="focusHistoryService.focusPrevious()">Focus previous</button>
import {FocusHistoryService} from 'ngx-focus-control';
...
constructor(public readonly focusHistoryService: FocusHistoryService) { }

License

MIT