Skip to content

Commit 49e534c

Browse files
committed
Adding a bunch of comments explaining things so that i don't lose my place
1 parent 74fc2e6 commit 49e534c

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

packages/@react-aria/focus/src/FocusScope.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ function useFocusContainment(scopeRef: RefObject<HTMLElement[]>, contain: boolea
229229
};
230230

231231
let onFocus = (e) => {
232+
// I think this onFocus is stealing the focus away from in DialogTrigger test,
233+
// the dialog is closed, at which point focus should be restored to the trigger,
234+
// it would appear that
235+
/**
236+
* dialog is blurred (this is the only blur called that makes it to document)
237+
* dialog is focused (caught from local element listener)
238+
* dialog is focused (global)
239+
* button is focused (global)
240+
* dialog is focused (local)
241+
* dialog is focused (global)
242+
*
243+
* it's fired on so many things so fast that i don't think onFocus actually fires on the button?
244+
*/
245+
232246
// If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),
233247
// restore focus to the previously focused node or the first tabbable element in the active scope.
234248
let isInAnyScope = isElementInAnyScope(e.target, scopes);
@@ -245,7 +259,6 @@ function useFocusContainment(scopeRef: RefObject<HTMLElement[]>, contain: boolea
245259
};
246260

247261
let onBlur = (e) => {
248-
249262
let isInAnyScope = isElementInAnyScope(e.relatedTarget, scopes);
250263

251264
if (!isInAnyScope) {
@@ -259,6 +272,9 @@ function useFocusContainment(scopeRef: RefObject<HTMLElement[]>, contain: boolea
259272
};
260273

261274
document.addEventListener('keydown', onKeyDown, false);
275+
/**
276+
* removing the two global listeners fixes dialog trigger, but breaks FocusScope, Dialog containment, and Popover containment
277+
*/
262278
document.addEventListener('focusin', onFocus, false);
263279
scope.forEach(element => element.addEventListener('focusin', onFocus, false));
264280
scope.forEach(element => element.addEventListener('focusout', onBlur, false));

packages/@react-aria/focus/src/focusSafely.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {getInteractionModality} from '@react-aria/interactions';
1818
* as page scrolling and screen reader issues with CSS transitions.
1919
*/
2020
export function focusSafely(element: HTMLElement) {
21-
// If the user is interating with a virtual cursor, e.g. screen reader, then
21+
// If the user is interacting with a virtual cursor, e.g. screen reader, then
2222
// wait until after any animated transitions that are currently occurring on
2323
// the page before shifting focus. This avoids issues with VoiceOver on iOS
2424
// causing the page to scroll when moving focus if the element is transitioning

packages/@react-aria/interactions/src/useFocusVisible.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ function setupGlobalFocusEvents() {
134134
// Register focus events on the window so they are sure to happen
135135
// before React's event listeners (registered on the document).
136136
window.addEventListener('focus', handleFocusEvent, true);
137-
window.addEventListener('blur', handleWindowBlur, true);
137+
window.addEventListener('blur', handleWindowBlur, true); // reverting this fixes the Picker test that's failing
138+
/**
139+
* it's happening because as a capture, it's getting a window blur when it shouldn't, when the spectrum-Menu is focused
140+
* I assume because of the blur on the trigger?
141+
* also, this is getting fired a LOT
142+
*/
138143

139144
if (typeof PointerEvent !== 'undefined') {
140145
document.addEventListener('pointerdown', handlePointerEvent, true);

packages/@react-spectrum/dialog/test/DialogTrigger.test.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ describe('DialogTrigger', function () {
225225
expect(tray).toBeVisible();
226226
});
227227

228-
// this one fails
228+
// see notes in focus scope, fails in .only mode as well
229229
it('should restore focus to the trigger when the dialog is closed', async function () {
230230
let {getByRole} = render(
231231
<Provider theme={theme}>
232232
<DialogTrigger>
233-
<ActionButton onFocus={() => console.log('focused trigger')}>Trigger</ActionButton>
233+
<ActionButton>Trigger</ActionButton>
234234
<Dialog>contents</Dialog>
235235
</DialogTrigger>
236236
</Provider>
@@ -264,11 +264,9 @@ describe('DialogTrigger', function () {
264264
expect(dialog).not.toBeInTheDocument();
265265
}); // wait for animation
266266

267-
console.log('just before fail');
268267
expect(document.activeElement).toBe(button);
269268
});
270269

271-
// this one fails
272270
it('should restore focus to the trigger when the dialog is closed from a hidden dismiss button', async function () {
273271
let {getByRole} = render(
274272
<Provider theme={theme}>
@@ -308,7 +306,6 @@ describe('DialogTrigger', function () {
308306
expect(document.activeElement).toBe(button);
309307
});
310308

311-
// fails
312309
it('should set aria-hidden on parent providers on mount and remove on unmount', async function () {
313310
let rootProviderRef = React.createRef();
314311
let {getByRole} = render(
@@ -349,7 +346,6 @@ describe('DialogTrigger', function () {
349346
expect(rootProviderRef.current.UNSAFE_getDOMNode()).not.toHaveAttribute('aria-hidden');
350347
});
351348

352-
// fails
353349
it('can be controlled', async function () {
354350
function Test({isOpen, onOpenChange}) {
355351
return (
@@ -412,7 +408,6 @@ describe('DialogTrigger', function () {
412408
}); // wait for animation
413409
});
414410

415-
// fails
416411
it('can be uncontrolled with defaultOpen', async function () {
417412
function Test({defaultOpen, onOpenChange}) {
418413
return (
@@ -451,7 +446,6 @@ describe('DialogTrigger', function () {
451446
}); // wait for animation
452447
});
453448

454-
// fails
455449
it('can be closed by buttons the user adds', async function () {
456450
function Test({defaultOpen, onOpenChange}) {
457451
return (
@@ -491,7 +485,6 @@ describe('DialogTrigger', function () {
491485
}); // wait for animation
492486
});
493487

494-
// fails
495488
it('can be closed by dismiss button in dialog', async function () {
496489
function Test({defaultOpen, onOpenChange}) {
497490
return (
@@ -531,7 +524,6 @@ describe('DialogTrigger', function () {
531524
}); // wait for animation
532525
});
533526

534-
// fails
535527
it('dismissable modals can be closed by clicking outside the dialog', async function () {
536528
function Test({defaultOpen, onOpenChange}) {
537529
return (
@@ -570,7 +562,6 @@ describe('DialogTrigger', function () {
570562
}); // wait for animation
571563
});
572564

573-
// fails
574565
it('non dismissable modals cannot be closed by clicking outside the dialog', async function () {
575566
function Test({defaultOpen, onOpenChange}) {
576567
return (
@@ -603,7 +594,6 @@ describe('DialogTrigger', function () {
603594
expect(onOpenChange).toHaveBeenCalledTimes(0);
604595
});
605596

606-
// fails
607597
it('mobile type modals should be closable by clicking outside the modal', async function () {
608598
matchMedia.useMediaQuery('(max-width: 700px)');
609599
function Test({defaultOpen, onOpenChange}) {
@@ -643,7 +633,6 @@ describe('DialogTrigger', function () {
643633
}); // wait for animation
644634
});
645635

646-
// fails
647636
it('non-modals can be closed by clicking outside the dialog regardless of isDismissable', async function () {
648637
function Test({defaultOpen, onOpenChange}) {
649638
return (
@@ -682,7 +671,6 @@ describe('DialogTrigger', function () {
682671
}); // wait for animation
683672
});
684673

685-
// fails
686674
it('disable closing dialog via escape key', async function () {
687675
let {getByRole} = render(
688676
<Provider theme={theme}>

0 commit comments

Comments
 (0)