ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - Raiper34/ngx-focus-control: Library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility.
Library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility. - Raiper34/ngx-focus-control
Visit Site

GitHub - Raiper34/ngx-focus-control: Library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility.

GitHub - Raiper34/ngx-focus-control: Library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility.

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) { }
  • Focus unleavable directive

does not allow leaving a focusable element when the provided condition is met.

<input placeholder="Input 1" class="input" [(ngModel)]="inputContent" [fuUnleavable]="inputContent.length < 5">

License

MIT

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory