Skip to content

Commit f0ed573

Browse files
committed
feat(cdk/a11y): Respond to PR feedback
1 parent 3ee15ef commit f0ed573

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

src/cdk/a11y/input-modality/input-modality-detector.spec.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,57 +30,57 @@ describe('InputModalityDetector', () => {
3030
it('should do nothing on non-browser platforms', () => {
3131
platform.isBrowser = false;
3232
detector = new InputModalityDetector(platform, ngZone, document);
33-
expect(detector.inputModality).toBe(null);
33+
expect(detector.mostRecentModality).toBe(null);
3434

3535
dispatchKeyboardEvent(document, 'keydown');
36-
expect(detector.inputModality).toBe(null);
36+
expect(detector.mostRecentModality).toBe(null);
3737

3838
dispatchMouseEvent(document, 'mousedown');
39-
expect(detector.inputModality).toBe(null);
39+
expect(detector.mostRecentModality).toBe(null);
4040

4141
dispatchTouchEvent(document, 'touchstart');
42-
expect(detector.inputModality).toBe(null);
42+
expect(detector.mostRecentModality).toBe(null);
4343
});
4444

4545
it('should detect keyboard input modality', () => {
4646
detector = new InputModalityDetector(platform, ngZone, document);
4747
dispatchKeyboardEvent(document, 'keydown');
48-
expect(detector.inputModality).toBe('keyboard');
48+
expect(detector.mostRecentModality).toBe('keyboard');
4949
});
5050

5151
it('should detect mouse input modality', () => {
5252
detector = new InputModalityDetector(platform, ngZone, document);
5353
dispatchMouseEvent(document, 'mousedown');
54-
expect(detector.inputModality).toBe('mouse');
54+
expect(detector.mostRecentModality).toBe('mouse');
5555
});
5656

5757
it('should detect touch input modality', () => {
5858
detector = new InputModalityDetector(platform, ngZone, document);
5959
dispatchTouchEvent(document, 'touchstart');
60-
expect(detector.inputModality).toBe('touch');
60+
expect(detector.mostRecentModality).toBe('touch');
6161
});
6262

6363
it('should detect changes in input modality', () => {
6464
detector = new InputModalityDetector(platform, ngZone, document);
6565

6666
dispatchKeyboardEvent(document, 'keydown');
67-
expect(detector.inputModality).toBe('keyboard');
67+
expect(detector.mostRecentModality).toBe('keyboard');
6868

6969
dispatchMouseEvent(document, 'mousedown');
70-
expect(detector.inputModality).toBe('mouse');
70+
expect(detector.mostRecentModality).toBe('mouse');
7171

7272
dispatchTouchEvent(document, 'touchstart');
73-
expect(detector.inputModality).toBe('touch');
73+
expect(detector.mostRecentModality).toBe('touch');
7474

7575
dispatchKeyboardEvent(document, 'keydown');
76-
expect(detector.inputModality).toBe('keyboard');
76+
expect(detector.mostRecentModality).toBe('keyboard');
7777
});
7878

7979
it('should emit changes in input modality', () => {
8080
detector = new InputModalityDetector(platform, ngZone, document);
8181
const emitted: InputModality[] = [];
82-
detector.inputModalityChange.subscribe((inputModality: InputModality) => {
83-
emitted.push(inputModality);
82+
detector.modalityChanges.subscribe((modality: InputModality) => {
83+
emitted.push(modality);
8484
});
8585

8686
expect(emitted.length).toBe(0);
@@ -112,7 +112,7 @@ describe('InputModalityDetector', () => {
112112
Object.defineProperty(event, 'buttons', {get: () => 0});
113113
dispatchEvent(document, event);
114114

115-
expect(detector.inputModality).toBe(null);
115+
expect(detector.mostRecentModality).toBe(null);
116116
});
117117

118118
it('should ignore fake screen-reader touch events', () => {
@@ -123,7 +123,7 @@ describe('InputModalityDetector', () => {
123123
Object.defineProperty(event, 'touches', {get: () => [{identifier: -1}]});
124124
dispatchEvent(document, event);
125125

126-
expect(detector.inputModality).toBe(null);
126+
expect(detector.mostRecentModality).toBe(null);
127127
});
128128

129129
it('should ignore certain modifier keys by default', () => {
@@ -134,13 +134,13 @@ describe('InputModalityDetector', () => {
134134
dispatchKeyboardEvent(document, 'keydown', META);
135135
dispatchKeyboardEvent(document, 'keydown', SHIFT);
136136

137-
expect(detector.inputModality).toBe(null);
137+
expect(detector.mostRecentModality).toBe(null);
138138
});
139139

140140
it('should not ignore modifier keys if specified', () => {
141141
detector = new InputModalityDetector(platform, ngZone, document, {ignoreKeys: []});
142142
dispatchKeyboardEvent(document, 'keydown', CONTROL);
143-
expect(detector.inputModality).toBe('keyboard');
143+
expect(detector.mostRecentModality).toBe('keyboard');
144144
});
145145

146146
it('should ignore additional keys if specified', () => {
@@ -150,18 +150,18 @@ describe('InputModalityDetector', () => {
150150
dispatchKeyboardEvent(document, 'keydown', B);
151151
dispatchKeyboardEvent(document, 'keydown', C);
152152

153-
expect(detector.inputModality).toBe(null);
153+
expect(detector.mostRecentModality).toBe(null);
154154
});
155155

156156
it('should ignore mouse events that occur too closely after a touch event', fakeAsync(() => {
157157
detector = new InputModalityDetector(platform, ngZone, document);
158158

159159
dispatchTouchEvent(document, 'touchstart');
160160
dispatchMouseEvent(document, 'mousedown');
161-
expect(detector.inputModality).toBe('touch');
161+
expect(detector.mostRecentModality).toBe('touch');
162162

163163
tick(TOUCH_BUFFER_MS);
164164
dispatchMouseEvent(document, 'mousedown');
165-
expect(detector.inputModality).toBe('mouse');
165+
expect(detector.mostRecentModality).toBe('mouse');
166166
}));
167167
});

src/cdk/a11y/input-modality/input-modality-detector.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ const modalityEventListenerOptions = normalizePassiveListenerOptions({
7272
/**
7373
* Service that detects the user's input modality.
7474
*
75-
* Note: This service will not update the input modality when a user is navigating with a screen
76-
* reader (e.g. linear navigation with VoiceOver, object navigation / browse mode with NVDA, virtual
77-
* PC cursor mode with JAWS). This is in part due to technical limitations (i.e. keyboard events
78-
* do not fire as expected in these modes) but is also arguably the correct behavior. Navigating
79-
* with a screen reader is akin to visually scanning a page, and should not be interpreted as actual
80-
* user input interaction.
75+
* This service does not update the input modality when a user navigates with a screen reader
76+
* (e.g. linear navigation with VoiceOver, object navigation / browse mode with NVDA, virtual PC
77+
* cursor mode with JAWS). This is in part due to technical limitations (i.e. keyboard events do not
78+
* fire as expected in these modes) but is also arguably the correct behavior. Navigating with a
79+
* screen reader is akin to visually scanning a page, and should not be interpreted as actual user
80+
* input interaction.
8181
*
8282
* When a user is not navigating but *interacting* with a screen reader, this service's behavior is
8383
* largely undefined and depends on the events fired. For example, in VoiceOver, no keyboard events
@@ -87,15 +87,15 @@ const modalityEventListenerOptions = normalizePassiveListenerOptions({
8787
@Injectable({ providedIn: 'root' })
8888
export class InputModalityDetector implements OnDestroy {
8989
/** Emits when the input modality changes. */
90-
readonly inputModalityChange: Observable<InputModality>;
90+
readonly modalityChanges: Observable<InputModality>;
9191

92-
/** Returns the most recently detected input modality. */
93-
get inputModality(): InputModality {
94-
return this._inputModality.value;
92+
/** The most recently detected input modality. */
93+
get mostRecentModality(): InputModality {
94+
return this._modality.value;
9595
}
9696

9797
/** The underlying BehaviorSubject that emits whenever an input modality is detected. */
98-
private readonly _inputModality = new BehaviorSubject<InputModality>(null);
98+
private readonly _modality = new BehaviorSubject<InputModality>(null);
9999

100100
/** Options for this InputModalityDetector. */
101101
private readonly _options: InputModalityDetectorOptions;
@@ -115,7 +115,7 @@ export class InputModalityDetector implements OnDestroy {
115115
// modality to keyboard.
116116
if (this._options?.ignoreKeys?.some(keyCode => keyCode === event.keyCode)) { return; }
117117

118-
this._inputModality.next('keyboard');
118+
this._modality.next('keyboard');
119119
}
120120

121121
/**
@@ -130,7 +130,7 @@ export class InputModalityDetector implements OnDestroy {
130130
// after the previous touch event.
131131
if (Date.now() - this._lastTouchMs < TOUCH_BUFFER_MS) { return; }
132132

133-
this._inputModality.next('mouse');
133+
this._modality.next('mouse');
134134
}
135135

136136
/**
@@ -144,7 +144,7 @@ export class InputModalityDetector implements OnDestroy {
144144
// triggered via mouse vs touch.
145145
this._lastTouchMs = Date.now();
146146

147-
this._inputModality.next('touch');
147+
this._modality.next('touch');
148148
}
149149

150150
constructor(
@@ -160,7 +160,7 @@ export class InputModalityDetector implements OnDestroy {
160160
};
161161

162162
// Only emit if the input modality changes, and skip the first emission as it's null.
163-
this.inputModalityChange = this._inputModality.pipe(distinctUntilChanged(), skip(1));
163+
this.modalityChanges = this._modality.pipe(distinctUntilChanged(), skip(1));
164164

165165
// If we're not in a browser, this service should do nothing, as there's no relevant input
166166
// modality to detect.

src/dev-app/input-modality/input-modality-detector-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class InputModalityDetectorDemo implements OnDestroy {
2424
inputModalityDetector: InputModalityDetector,
2525
ngZone: NgZone,
2626
) {
27-
inputModalityDetector.inputModalityChange
27+
inputModalityDetector.modalityChanges
2828
.pipe(takeUntil(this._destroyed))
2929
.subscribe(modality => ngZone.run(() => { this._modality = modality; }));
3030
}

0 commit comments

Comments
 (0)