Skip to content

Commit 1dd4d3f

Browse files
ktaborssnowystingerdevongovett
authored
Improving Firefox Popover synthetic blur on disabled button (#4670)
* Improving Firefox Popover open with blur on disabled * comment improvements Co-authored-by: Robert Snow <[email protected]> * Update comment packages/@react-aria/focus/src/FocusScope.tsx Co-authored-by: Devon Govett <[email protected]> * updated relatedTaget for synthetic blurs --------- Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Devon Govett <[email protected]>
1 parent 2991179 commit 1dd4d3f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ function useFocusContainment(scopeRef: RefObject<Element[]>, contain: boolean) {
382382
};
383383
}, [scopeRef, contain]);
384384

385+
// This is a useLayoutEffect so it is guaranteed to run before our async synthetic blur
385386
// eslint-disable-next-line arrow-body-style
386-
useEffect(() => {
387+
useLayoutEffect(() => {
387388
return () => {
388389
if (raf.current) {
389390
cancelAnimationFrame(raf.current);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ export function useSyntheticBlurEvent<Target = Element>(onBlur: (e: ReactFocusEv
118118
stateRef.current.observer = new MutationObserver(() => {
119119
if (stateRef.current.isFocused && target.disabled) {
120120
stateRef.current.observer.disconnect();
121-
target.dispatchEvent(new FocusEvent('blur'));
122-
target.dispatchEvent(new FocusEvent('focusout', {bubbles: true}));
121+
let relatedTargetEl = target === document.activeElement ? null : document.activeElement;
122+
target.dispatchEvent(new FocusEvent('blur', {relatedTarget: relatedTargetEl}));
123+
target.dispatchEvent(new FocusEvent('focusout', {bubbles: true, relatedTarget: relatedTargetEl}));
123124
}
124125
});
125126

0 commit comments

Comments
 (0)