a11y-module.d-DBHGyKoh.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import * as i0 from '@angular/core';
  2. import { NgZone, Injector, OnDestroy, AfterContentInit, OnChanges, DoCheck, SimpleChanges, InjectionToken } from '@angular/core';
  3. import { ObserversModule } from './observers/index.js';
  4. import { C as CdkMonitorFocus } from './focus-monitor.d-CvvJeQRc.js';
  5. /**
  6. * Configuration for the isFocusable method.
  7. */
  8. declare class IsFocusableConfig {
  9. /**
  10. * Whether to count an element as focusable even if it is not currently visible.
  11. */
  12. ignoreVisibility: boolean;
  13. }
  14. /**
  15. * Utility for checking the interactivity of an element, such as whether it is focusable or
  16. * tabbable.
  17. */
  18. declare class InteractivityChecker {
  19. private _platform;
  20. constructor(...args: unknown[]);
  21. /**
  22. * Gets whether an element is disabled.
  23. *
  24. * @param element Element to be checked.
  25. * @returns Whether the element is disabled.
  26. */
  27. isDisabled(element: HTMLElement): boolean;
  28. /**
  29. * Gets whether an element is visible for the purposes of interactivity.
  30. *
  31. * This will capture states like `display: none` and `visibility: hidden`, but not things like
  32. * being clipped by an `overflow: hidden` parent or being outside the viewport.
  33. *
  34. * @returns Whether the element is visible.
  35. */
  36. isVisible(element: HTMLElement): boolean;
  37. /**
  38. * Gets whether an element can be reached via Tab key.
  39. * Assumes that the element has already been checked with isFocusable.
  40. *
  41. * @param element Element to be checked.
  42. * @returns Whether the element is tabbable.
  43. */
  44. isTabbable(element: HTMLElement): boolean;
  45. /**
  46. * Gets whether an element can be focused by the user.
  47. *
  48. * @param element Element to be checked.
  49. * @param config The config object with options to customize this method's behavior
  50. * @returns Whether the element is focusable.
  51. */
  52. isFocusable(element: HTMLElement, config?: IsFocusableConfig): boolean;
  53. static ɵfac: i0.ɵɵFactoryDeclaration<InteractivityChecker, never>;
  54. static ɵprov: i0.ɵɵInjectableDeclaration<InteractivityChecker>;
  55. }
  56. /**
  57. * Class that allows for trapping focus within a DOM element.
  58. *
  59. * This class currently uses a relatively simple approach to focus trapping.
  60. * It assumes that the tab order is the same as DOM order, which is not necessarily true.
  61. * Things like `tabIndex > 0`, flex `order`, and shadow roots can cause the two to be misaligned.
  62. */
  63. declare class FocusTrap {
  64. readonly _element: HTMLElement;
  65. private _checker;
  66. readonly _ngZone: NgZone;
  67. readonly _document: Document;
  68. /** @breaking-change 20.0.0 param to become required */
  69. readonly _injector?: Injector | undefined;
  70. private _startAnchor;
  71. private _endAnchor;
  72. private _hasAttached;
  73. protected startAnchorListener: () => boolean;
  74. protected endAnchorListener: () => boolean;
  75. /** Whether the focus trap is active. */
  76. get enabled(): boolean;
  77. set enabled(value: boolean);
  78. protected _enabled: boolean;
  79. constructor(_element: HTMLElement, _checker: InteractivityChecker, _ngZone: NgZone, _document: Document, deferAnchors?: boolean,
  80. /** @breaking-change 20.0.0 param to become required */
  81. _injector?: Injector | undefined);
  82. /** Destroys the focus trap by cleaning up the anchors. */
  83. destroy(): void;
  84. /**
  85. * Inserts the anchors into the DOM. This is usually done automatically
  86. * in the constructor, but can be deferred for cases like directives with `*ngIf`.
  87. * @returns Whether the focus trap managed to attach successfully. This may not be the case
  88. * if the target element isn't currently in the DOM.
  89. */
  90. attachAnchors(): boolean;
  91. /**
  92. * Waits for the zone to stabilize, then focuses the first tabbable element.
  93. * @returns Returns a promise that resolves with a boolean, depending
  94. * on whether focus was moved successfully.
  95. */
  96. focusInitialElementWhenReady(options?: FocusOptions): Promise<boolean>;
  97. /**
  98. * Waits for the zone to stabilize, then focuses
  99. * the first tabbable element within the focus trap region.
  100. * @returns Returns a promise that resolves with a boolean, depending
  101. * on whether focus was moved successfully.
  102. */
  103. focusFirstTabbableElementWhenReady(options?: FocusOptions): Promise<boolean>;
  104. /**
  105. * Waits for the zone to stabilize, then focuses
  106. * the last tabbable element within the focus trap region.
  107. * @returns Returns a promise that resolves with a boolean, depending
  108. * on whether focus was moved successfully.
  109. */
  110. focusLastTabbableElementWhenReady(options?: FocusOptions): Promise<boolean>;
  111. /**
  112. * Get the specified boundary element of the trapped region.
  113. * @param bound The boundary to get (start or end of trapped region).
  114. * @returns The boundary element.
  115. */
  116. private _getRegionBoundary;
  117. /**
  118. * Focuses the element that should be focused when the focus trap is initialized.
  119. * @returns Whether focus was moved successfully.
  120. */
  121. focusInitialElement(options?: FocusOptions): boolean;
  122. /**
  123. * Focuses the first tabbable element within the focus trap region.
  124. * @returns Whether focus was moved successfully.
  125. */
  126. focusFirstTabbableElement(options?: FocusOptions): boolean;
  127. /**
  128. * Focuses the last tabbable element within the focus trap region.
  129. * @returns Whether focus was moved successfully.
  130. */
  131. focusLastTabbableElement(options?: FocusOptions): boolean;
  132. /**
  133. * Checks whether the focus trap has successfully been attached.
  134. */
  135. hasAttached(): boolean;
  136. /** Get the first tabbable element from a DOM subtree (inclusive). */
  137. private _getFirstTabbableElement;
  138. /** Get the last tabbable element from a DOM subtree (inclusive). */
  139. private _getLastTabbableElement;
  140. /** Creates an anchor element. */
  141. private _createAnchor;
  142. /**
  143. * Toggles the `tabindex` of an anchor, based on the enabled state of the focus trap.
  144. * @param isEnabled Whether the focus trap is enabled.
  145. * @param anchor Anchor on which to toggle the tabindex.
  146. */
  147. private _toggleAnchorTabIndex;
  148. /**
  149. * Toggles the`tabindex` of both anchors to either trap Tab focus or allow it to escape.
  150. * @param enabled: Whether the anchors should trap Tab.
  151. */
  152. protected toggleAnchors(enabled: boolean): void;
  153. /** Executes a function when the zone is stable. */
  154. private _executeOnStable;
  155. }
  156. /**
  157. * Factory that allows easy instantiation of focus traps.
  158. */
  159. declare class FocusTrapFactory {
  160. private _checker;
  161. private _ngZone;
  162. private _document;
  163. private _injector;
  164. constructor(...args: unknown[]);
  165. /**
  166. * Creates a focus-trapped region around the given element.
  167. * @param element The element around which focus will be trapped.
  168. * @param deferCaptureElements Defers the creation of focus-capturing elements to be done
  169. * manually by the user.
  170. * @returns The created focus trap instance.
  171. */
  172. create(element: HTMLElement, deferCaptureElements?: boolean): FocusTrap;
  173. static ɵfac: i0.ɵɵFactoryDeclaration<FocusTrapFactory, never>;
  174. static ɵprov: i0.ɵɵInjectableDeclaration<FocusTrapFactory>;
  175. }
  176. /** Directive for trapping focus within a region. */
  177. declare class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoCheck {
  178. private _elementRef;
  179. private _focusTrapFactory;
  180. /** Underlying FocusTrap instance. */
  181. focusTrap: FocusTrap;
  182. /** Previously focused element to restore focus to upon destroy when using autoCapture. */
  183. private _previouslyFocusedElement;
  184. /** Whether the focus trap is active. */
  185. get enabled(): boolean;
  186. set enabled(value: boolean);
  187. /**
  188. * Whether the directive should automatically move focus into the trapped region upon
  189. * initialization and return focus to the previous activeElement upon destruction.
  190. */
  191. autoCapture: boolean;
  192. constructor(...args: unknown[]);
  193. ngOnDestroy(): void;
  194. ngAfterContentInit(): void;
  195. ngDoCheck(): void;
  196. ngOnChanges(changes: SimpleChanges): void;
  197. private _captureFocus;
  198. static ɵfac: i0.ɵɵFactoryDeclaration<CdkTrapFocus, never>;
  199. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkTrapFocus, "[cdkTrapFocus]", ["cdkTrapFocus"], { "enabled": { "alias": "cdkTrapFocus"; "required": false; }; "autoCapture": { "alias": "cdkTrapFocusAutoCapture"; "required": false; }; }, {}, never, never, true, never>;
  200. static ngAcceptInputType_enabled: unknown;
  201. static ngAcceptInputType_autoCapture: unknown;
  202. }
  203. /** Possible politeness levels. */
  204. type AriaLivePoliteness = 'off' | 'polite' | 'assertive';
  205. declare const LIVE_ANNOUNCER_ELEMENT_TOKEN: InjectionToken<HTMLElement | null>;
  206. /**
  207. * @docs-private
  208. * @deprecated No longer used, will be removed.
  209. * @breaking-change 21.0.0
  210. */
  211. declare function LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY(): null;
  212. /** Object that can be used to configure the default options for the LiveAnnouncer. */
  213. interface LiveAnnouncerDefaultOptions {
  214. /** Default politeness for the announcements. */
  215. politeness?: AriaLivePoliteness;
  216. /** Default duration for the announcement messages. */
  217. duration?: number;
  218. }
  219. /** Injection token that can be used to configure the default options for the LiveAnnouncer. */
  220. declare const LIVE_ANNOUNCER_DEFAULT_OPTIONS: InjectionToken<LiveAnnouncerDefaultOptions>;
  221. declare class LiveAnnouncer implements OnDestroy {
  222. private _ngZone;
  223. private _defaultOptions;
  224. private _liveElement;
  225. private _document;
  226. private _previousTimeout;
  227. private _currentPromise;
  228. private _currentResolve;
  229. constructor(...args: unknown[]);
  230. /**
  231. * Announces a message to screen readers.
  232. * @param message Message to be announced to the screen reader.
  233. * @returns Promise that will be resolved when the message is added to the DOM.
  234. */
  235. announce(message: string): Promise<void>;
  236. /**
  237. * Announces a message to screen readers.
  238. * @param message Message to be announced to the screen reader.
  239. * @param politeness The politeness of the announcer element.
  240. * @returns Promise that will be resolved when the message is added to the DOM.
  241. */
  242. announce(message: string, politeness?: AriaLivePoliteness): Promise<void>;
  243. /**
  244. * Announces a message to screen readers.
  245. * @param message Message to be announced to the screen reader.
  246. * @param duration Time in milliseconds after which to clear out the announcer element. Note
  247. * that this takes effect after the message has been added to the DOM, which can be up to
  248. * 100ms after `announce` has been called.
  249. * @returns Promise that will be resolved when the message is added to the DOM.
  250. */
  251. announce(message: string, duration?: number): Promise<void>;
  252. /**
  253. * Announces a message to screen readers.
  254. * @param message Message to be announced to the screen reader.
  255. * @param politeness The politeness of the announcer element.
  256. * @param duration Time in milliseconds after which to clear out the announcer element. Note
  257. * that this takes effect after the message has been added to the DOM, which can be up to
  258. * 100ms after `announce` has been called.
  259. * @returns Promise that will be resolved when the message is added to the DOM.
  260. */
  261. announce(message: string, politeness?: AriaLivePoliteness, duration?: number): Promise<void>;
  262. /**
  263. * Clears the current text from the announcer element. Can be used to prevent
  264. * screen readers from reading the text out again while the user is going
  265. * through the page landmarks.
  266. */
  267. clear(): void;
  268. ngOnDestroy(): void;
  269. private _createLiveElement;
  270. /**
  271. * Some browsers won't expose the accessibility node of the live announcer element if there is an
  272. * `aria-modal` and the live announcer is outside of it. This method works around the issue by
  273. * pointing the `aria-owns` of all modals to the live announcer element.
  274. */
  275. private _exposeAnnouncerToModals;
  276. static ɵfac: i0.ɵɵFactoryDeclaration<LiveAnnouncer, never>;
  277. static ɵprov: i0.ɵɵInjectableDeclaration<LiveAnnouncer>;
  278. }
  279. /**
  280. * A directive that works similarly to aria-live, but uses the LiveAnnouncer to ensure compatibility
  281. * with a wider range of browsers and screen readers.
  282. */
  283. declare class CdkAriaLive implements OnDestroy {
  284. private _elementRef;
  285. private _liveAnnouncer;
  286. private _contentObserver;
  287. private _ngZone;
  288. /** The aria-live politeness level to use when announcing messages. */
  289. get politeness(): AriaLivePoliteness;
  290. set politeness(value: AriaLivePoliteness);
  291. private _politeness;
  292. /** Time in milliseconds after which to clear out the announcer element. */
  293. duration: number;
  294. private _previousAnnouncedText?;
  295. private _subscription;
  296. constructor(...args: unknown[]);
  297. ngOnDestroy(): void;
  298. static ɵfac: i0.ɵɵFactoryDeclaration<CdkAriaLive, never>;
  299. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkAriaLive, "[cdkAriaLive]", ["cdkAriaLive"], { "politeness": { "alias": "cdkAriaLive"; "required": false; }; "duration": { "alias": "cdkAriaLiveDuration"; "required": false; }; }, {}, never, never, true, never>;
  300. }
  301. declare class A11yModule {
  302. constructor();
  303. static ɵfac: i0.ɵɵFactoryDeclaration<A11yModule, never>;
  304. static ɵmod: i0.ɵɵNgModuleDeclaration<A11yModule, never, [typeof ObserversModule, typeof CdkAriaLive, typeof CdkTrapFocus, typeof CdkMonitorFocus], [typeof CdkAriaLive, typeof CdkTrapFocus, typeof CdkMonitorFocus]>;
  305. static ɵinj: i0.ɵɵInjectorDeclaration<A11yModule>;
  306. }
  307. export { A11yModule as A, CdkTrapFocus as C, FocusTrapFactory as F, InteractivityChecker as I, LiveAnnouncer as L, FocusTrap as a, IsFocusableConfig as b, CdkAriaLive as c, LIVE_ANNOUNCER_ELEMENT_TOKEN as e, LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY as f, LIVE_ANNOUNCER_DEFAULT_OPTIONS as h };
  308. export type { AriaLivePoliteness as d, LiveAnnouncerDefaultOptions as g };