Skip to content

Commit ef3064e

Browse files
committed
docs(readme): update readme with examples and fix focus if directive presentation
1 parent e6f8d56 commit ef3064e

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,70 @@ See [DEMO](https://ngx-focus-control.netlify.app/) app for usage.
3737
# Directives
3838
- ### Focus auto directive
3939
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.
40+
```angular2html
41+
<input placeholder="Input" class="input" [fuAuto]="500">
42+
```
4043
- ### Focus control directive
4144
allows the user to manually define the next and/or previous focus target.
45+
```angular2html
46+
<input placeholder="Input 1" class="input" id="input-1" [fuControl]="{next: '#input-3', previous: input2}">
47+
<input #input2 placeholder="Input 2" class="input" id="input-2" [fuControl]="{next: '#input-1', previous: '#input-3'}">
48+
<input placeholder="Input 3" class="input" id="input-3" [fuControl]="{next: input2, previous: '#input-1'}">
49+
```
4250
- ### Focus selector directive
4351
allows the user to manually define the next and previous focus target by the given query selector.
52+
```angular2html
53+
<input placeholder="Input 1" class="input focus-selector-item" [fuSelector]="'.focus-selector-item'">
54+
<input placeholder="Input 2" class="input">
55+
<input placeholder="Input 3" class="input focus-selector-item" [fuSelector]="'.focus-selector-item'">
56+
```
4457
- ### Focus group directive
4558
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.
59+
```angular2html
60+
<div tabindex="0" id="group-1" class="box focus-selector-parent" [fuGroup]="{selector: '.focus-group-item'}">
61+
<div class="subtitle has-text-black">Group</div>
62+
<input type="text" tabindex="-1" placeholder="Input 1" class="input focus-group-item" id="input-1">
63+
<input type="text" tabindex="-1" placeholder="Input 2" class="input focus-group-item" id="input-2">
64+
</div>
65+
```
4666
- ### Focus lock directive
4767
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.
68+
```angular2html
69+
<div id="lock-1" class="box focus-selector-parent" fuLock>
70+
<input type="text" placeholder="Input 1" class="input" id="input-1">
71+
<input type="text" placeholder="Input 2" class="input" id="input-2">
72+
<input type="text" placeholder="Input 3" class="input" id="input-3">
73+
</div>
74+
```
4875
- ### Focus if directive
4976
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.
50-
- ### Focus history directive
51-
stores focused elements into history and thanks to history service `FocusHistoryService` you can go back in focus history using `focusHistoryService.focusPrevious()`.
77+
```angular2html
78+
<input type="text" placeholder="Input 16" class="input" id="input-16" [fuIf]="condition">
79+
<input type="text" placeholder="Input 17" class="input" id="input-17" [fuIf]="observable$">
80+
```
5281
- ### Focus switch directives
5382
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).
83+
```angular2html
84+
<ng-container [fuSwitch]="switchValue">
85+
<input type="text" placeholder="Input 1" class="input" id="input-1" [fuCase]="'option-1'">
86+
<input type="text" placeholder="Input 2" class="input" id="input-2" [fuCase]="'option-2'">
87+
<input type="text" placeholder="Input 3" class="input" id="input-3" [fuCase]="'option-3'">
88+
<input type="text" placeholder="Input 4 Default" class="input" id="input-4" fuDefault>
89+
</ng-container>
90+
<button class="button is-success" (click)="switchValue = 'option-1'">Focus Input 1</button>
91+
<button class="button is-success" (click)="switchValue = 'option-2'">Focus Input 2</button>
92+
<button class="button is-success" (click)="switchValue = 'option-3'">Focus Input 3</button>
93+
<button class="button is-success" (click)="switchValue = 'option-100'">Switch to non-existing value</button>
94+
```
95+
- ### Focus history directive
96+
stores focused elements into history and thanks to history service `FocusHistoryService` you can go back in focus history using `focusHistoryService.focusPrevious()`.
97+
```angular2html
98+
<input type="text" placeholder="Input 1" class="input" id="input-1" fuHistory>
99+
<input type="text" placeholder="Input 2" class="input" id="input-2" fuHistory>
100+
<button class="button is-info" (click)="focusHistoryService.focusPrevious()">Focus previous</button>
101+
```
102+
```ts
103+
import {FocusHistoryService} from 'ngx-focus-control';
104+
...
105+
constructor(public readonly focusHistoryService: FocusHistoryService) { }
106+
```

src/app/focus-if-directive/focus-if-directive.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class FocusIfDirectiveComponent implements OnInit {
1212
observable$ = new Subject<boolean>();
1313

1414
focusIfCode = `<input type="text" placeholder="Input 16" class="input" id="input-16" [fuIf]="condition">
15-
<input type="text" placeholder="Input 17" class="input" id="input-17" [fuObs]="observable$">`;
15+
<input type="text" placeholder="Input 17" class="input" id="input-17" [fuIf]="observable$">`;
1616

1717
constructor() { }
1818

0 commit comments

Comments
 (0)