Library to provide tools to work with focus and focusable elements to improve user interfaces and accessibility.
npm install ngx-focus-control



!npm bundle size
!NPM



npm install ngx-focus-control --save
then add NgxFocusControlModule into module imports
``typescript
import {NgxFocusControlModule} from 'ngx-focus-control';
@NgModule({
// ...
imports: [
// ...
NgxFocusControlModule,
// ...
],
// ...
})
`
html
`
- ### Focus control directive
allows the user to manually define the next and/or previous focus target.
`html
`
- ### Focus selector directive
allows the user to manually define the next and previous focus target by the given query selector.
`html
`
- ### 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.
`html
Group
`
- ### 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.
`html
`
- ### 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.
`html
`
- ### 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).
`html
`
- ### Focus history directive
stores focused elements into history and thanks to history service FocusHistoryService you can go back in focus history using focusHistoryService.focusPrevious().
`html
`
`ts
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.
`html
``