Ngx focus control

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

npm versionCircleCICoverage StatusGitHub issuesnpm bundle sizeNPMdemostack blitzGitter
logo
Angular library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility.
npm install ngx-focus-control --save

Focus switch, case and default directive

Focus switch directive 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).


Example shows 4 inputs, that should be focused based on the variable provided in the focus switch. You can change the variable with a button click.


Code


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