projects/storefrontlib/layout/a11y/keyboard-focus/escape/escape-focus.service.ts
Properties |
|
Methods |
constructor(selectFocusUtil: SelectFocusUtility)
|
||||||
|
Parameters :
|
| handleEscape | ||||||||||||
handleEscape(host: HTMLElement, config: EscapeFocusConfig, event: KeyboardEvent)
|
||||||||||||
|
Parameters :
Returns :
void
|
| shouldFocus | ||||||
shouldFocus(config: EscapeFocusConfig)
|
||||||
|
Parameters :
Returns :
boolean
|
| clear | ||||||
clear(group?: string)
|
||||||
|
Inherited from
PersistFocusService
|
||||||
|
Defined in
PersistFocusService:38
|
||||||
|
Clears the persisted keyboard focus state globally or for the given group.
Parameters :
Returns :
void
|
| get | ||||||
get(group?: string)
|
||||||
|
Inherited from
PersistFocusService
|
||||||
|
Defined in
PersistFocusService:21
|
||||||
|
Parameters :
Returns :
string
|
| getPersistenceGroup | |||||||||
getPersistenceGroup(host: HTMLElement, config?: PersistFocusConfig)
|
|||||||||
|
Inherited from
PersistFocusService
|
|||||||||
|
Defined in
PersistFocusService:46
|
|||||||||
|
Returns the group for the host element based on the configured group or
by the
Parameters :
Returns :
string
|
| set |
set(key: string, group?: string)
|
|
Inherited from
PersistFocusService
|
|
Defined in
PersistFocusService:29
|
|
Persist the keyboard focus state for the given key. The focus is stored globally or for the given group.
Returns :
void
|
| Protected focus |
Default value : new Map<string, string>()
|
|
Inherited from
PersistFocusService
|
|
Defined in
PersistFocusService:19
|
import { Injectable } from '@angular/core';
import { EscapeFocusConfig } from '../keyboard-focus.model';
import { PersistFocusService } from '../persist/persist-focus.service';
import { SelectFocusUtility } from '../services/select-focus.util';
@Injectable({
providedIn: 'root',
})
export class EscapeFocusService extends PersistFocusService {
constructor(protected selectFocusUtil: SelectFocusUtility) {
super();
}
shouldFocus(config: EscapeFocusConfig): boolean {
return !!config?.focusOnEscape;
}
handleEscape(
host: HTMLElement,
config: EscapeFocusConfig,
event: KeyboardEvent
): void {
if (this.shouldFocus(config)) {
if (host !== event.target) {
host.focus({ preventScroll: true });
event.preventDefault();
event.stopPropagation();
} else {
if (config?.focusOnDoubleEscape) {
this.selectFocusUtil
.findFirstFocusable(host, { autofocus: true })
?.focus();
}
}
}
}
}