Skip to content

Commit e132626

Browse files
committed
Add continuePropagation to focus events
1 parent 8edaa62 commit e132626

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

packages/react-interactions/accessibility/src/FocusManager.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const FocusManager = React.forwardRef(
6262
});
6363
const focusWithin = useFocusWithin({
6464
onBlurWithin: function(event) {
65+
if (!containFocus) {
66+
event.continuePropagation();
67+
}
6568
const lastNode = event.target;
6669
if (lastNode) {
6770
requestAnimationFrame(() => {

packages/react-interactions/accessibility/src/__tests__/FocusManager-test.internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ describe('FocusManager', () => {
141141
expect(document.activeElement).toBe(button2Ref.current);
142142
// Focus should be restored to the contained area
143143
const rAF = window.requestAnimationFrame;
144-
window.requestAnimationFrame = (x) => setTimeout(x);
145-
input3Ref.current.focus();
144+
window.requestAnimationFrame = x => setTimeout(x);
145+
input3Ref.current.focus();
146146
jest.advanceTimersByTime(1);
147147
window.requestAnimationFrame = rAF;
148148
expect(document.activeElement).toBe(button2Ref.current);

packages/react-interactions/events/src/dom/Focus.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type FocusEvent = {|
2626
type: FocusEventType | FocusWithinEventType,
2727
pointerType: PointerType,
2828
timeStamp: number,
29+
continuePropagation: () => void,
2930
|};
3031

3132
type FocusState = {
@@ -93,6 +94,14 @@ function createFocusEvent(
9394
type,
9495
pointerType,
9596
timeStamp: context.getTimeStamp(),
97+
// We don't use stopPropagation, as the default behavior
98+
// is to not propagate. Plus, there might be confusion
99+
// using stopPropagation as we don't actually stop
100+
// native propagation from working, but instead only
101+
// allow propagation to the others keyboard responders.
102+
continuePropagation() {
103+
context.continuePropagation();
104+
},
96105
};
97106
}
98107

0 commit comments

Comments
 (0)