File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
src/cdk/a11y/interactivity-checker
tools/public_api_guard/cdk Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { Platform } from '@angular/cdk/platform' ;
2
2
import { inject } from '@angular/core/testing' ;
3
- import { InteractivityChecker } from './interactivity-checker' ;
3
+ import { InteractivityChecker , IsFocusableConfig } from './interactivity-checker' ;
4
4
5
5
describe ( 'InteractivityChecker' , ( ) => {
6
6
let platform : Platform ;
@@ -153,6 +153,17 @@ describe('InteractivityChecker', () => {
153
153
. toBe ( false , 'Expected element with `display: none` to not be visible' ) ;
154
154
} ) ;
155
155
156
+ it ( 'should return true for a `display: none` element with ignoreVisibility' , ( ) => {
157
+ testContainerElement . innerHTML =
158
+ `<input style="display: none;">` ;
159
+ const input = testContainerElement . querySelector ( 'input' ) as HTMLElement ;
160
+ let config = new IsFocusableConfig ( ) ;
161
+ config . ignoreVisibility = true ;
162
+
163
+ expect ( checker . isFocusable ( input , config ) )
164
+ . toBe ( true , 'Expected element with `display: none` to be focusable' ) ;
165
+ } ) ;
166
+
156
167
it ( 'should return false for the child of a `display: none` element' , ( ) => {
157
168
testContainerElement . innerHTML =
158
169
`<div style="display: none;">
Original file line number Diff line number Diff line change 9
9
import { Platform } from '@angular/cdk/platform' ;
10
10
import { Injectable } from '@angular/core' ;
11
11
12
+ /**
13
+ * Configuration for the isFocusable method.
14
+ */
15
+ export class IsFocusableConfig {
16
+ /**
17
+ * Whether to count an element as focusable even if it is not currently visible.
18
+ */
19
+ ignoreVisibility : boolean = false ;
20
+ }
12
21
13
22
// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
14
23
// Methods like `isTabbable` are only covering specific edge-cases for the browsers which are
@@ -132,12 +141,14 @@ export class InteractivityChecker {
132
141
* Gets whether an element can be focused by the user.
133
142
*
134
143
* @param element Element to be checked.
144
+ * @param config The config object with options to customize this method's behavior
135
145
* @returns Whether the element is focusable.
136
146
*/
137
- isFocusable ( element : HTMLElement ) : boolean {
147
+ isFocusable ( element : HTMLElement , config ?: IsFocusableConfig ) : boolean {
138
148
// Perform checks in order of left to most expensive.
139
149
// Again, naive approach that does not capture many edge cases and browser quirks.
140
- return isPotentiallyFocusable ( element ) && ! this . isDisabled ( element ) && this . isVisible ( element ) ;
150
+ return isPotentiallyFocusable ( element ) && ! this . isDisabled ( element ) &&
151
+ ( config ?. ignoreVisibility || this . isVisible ( element ) ) ;
141
152
}
142
153
143
154
}
Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ export interface Highlightable extends ListKeyManagerOption {
181
181
export declare class InteractivityChecker {
182
182
constructor ( _platform : Platform ) ;
183
183
isDisabled ( element : HTMLElement ) : boolean ;
184
- isFocusable ( element : HTMLElement ) : boolean ;
184
+ isFocusable ( element : HTMLElement , config ?: IsFocusableConfig ) : boolean ;
185
185
isTabbable ( element : HTMLElement ) : boolean ;
186
186
isVisible ( element : HTMLElement ) : boolean ;
187
187
static ɵfac : i0 . ɵɵFactoryDef < InteractivityChecker , never > ;
@@ -190,6 +190,10 @@ export declare class InteractivityChecker {
190
190
191
191
export declare function isFakeMousedownFromScreenReader ( event : MouseEvent ) : boolean ;
192
192
193
+ export declare class IsFocusableConfig {
194
+ ignoreVisibility : boolean ;
195
+ }
196
+
193
197
export declare class ListKeyManager < T extends ListKeyManagerOption > {
194
198
get activeItem ( ) : T | null ;
195
199
get activeItemIndex ( ) : number | null ;
You can’t perform that action at this time.
0 commit comments