Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react-interactions] Refine custom active element blur logic #17354

Merged
merged 2 commits into from
Nov 13, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Nov 13, 2019

This is a follow up to #17291. Specifically, these PR tackles three things:

  • Has a much better event name for what the actions occurring. Specifically: onDetachedVisibleNode -> onBeforeFocusedElementDetached
  • Provides another callback that lets the user know the active blur has occurred on the removed node, this event is onFocusedElementDetached .
  • Fixes a bug where where a focused active element is removed as part of a larger sub-tree, where the active element isn't removed directly, but an ancestor above it is. We now use the beforeRemoveInstance to correctly unify this logic (removing it from the removeChild and removeChildFromContainer methods)

Why do we need two events? What is the for?

These callbacks are to help with our experimental internal accessibility work at Facebook. There are various ways to tackle this problem. I've been working closely with @tatermelon (Tatiana from the accessibility team) to guide this implementation internally and apply it.

The problem these tackle are when active elements (elements that are focused on the document) are unmounted. This is a big problem with accessibility and it's been a big problem that folks have tried to tackle for a while with hacks. The realism is that there's no real good way to do this in user-land today, which is evident by how many websites simply don't handle this use-case.

This problem is made more evident with the introduction of Suspense fallbacks, where content if focused for a spinner, but is then removed to show the actual real content after X time. We need some way to know that this has occurred, so we can re-align with the document and imperatively move focus to the right node.

Two events are essential here:

  • onBeforeFocusedElementDetached fires before the active focused element is removed from the DOM. This is the perfect place to work out the "before" state, find what nodes are in view and do some calculations needed for the actual active blur event.
  • onFocusedElementDetached fires after all the changes have been committed and it's time to use the logic we stored in the before event, to work out what node we should imperatively focus next.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 13, 2019

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit eb5ba18:

Sandbox Source
romantic-mendeleev-jsixs Configuration

@sizebot
Copy link

sizebot commented Nov 13, 2019

Details of bundled changes.

Comparing: b53ea6c...eb5ba18

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.46 KB 10.46 KB 3.56 KB 3.57 KB NODE_PROD
react-dom-unstable-flight-server.browser.production.min.js 0.0% 🔺+0.1% 2.64 KB 2.64 KB 1.25 KB 1.25 KB NODE_PROD
react-dom-unstable-flight-client.development.js 0.0% 0.0% 8.7 KB 8.7 KB 2.59 KB 2.59 KB UMD_DEV
react-dom.development.js +0.1% +0.1% 953.15 KB 953.79 KB 215.44 KB 215.59 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.87 KB 3.87 KB 1.54 KB 1.54 KB UMD_DEV
react-dom-unstable-flight-server.node.production.min.js 0.0% 🔺+0.1% 2.8 KB 2.8 KB 1.27 KB 1.28 KB NODE_PROD
react-dom.production.min.js 0.0% 0.0% 116.24 KB 116.26 KB 37.46 KB 37.47 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.2 KB 1.2 KB 701 B 702 B UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.81 KB 119.83 KB 38.51 KB 38.52 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 947.26 KB 947.9 KB 213.87 KB 214.02 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.7 KB 3.7 KB 1.49 KB 1.49 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 116.38 KB 116.41 KB 36.83 KB 36.83 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.13 KB 60.13 KB 15.79 KB 15.79 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.04 KB 1.04 KB 632 B 633 B NODE_PROD
react-dom.profiling.min.js 0.0% 0.0% 120.07 KB 120.1 KB 37.87 KB 37.88 KB NODE_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.72 KB 10.72 KB 3.66 KB 3.67 KB UMD_PROD
react-dom-unstable-flight-server.browser.production.min.js 0.0% 🔺+0.1% 2.83 KB 2.83 KB 1.32 KB 1.33 KB UMD_PROD
react-dom-unstable-flight-server.browser.development.js 0.0% 0.0% 9.12 KB 9.12 KB 3.01 KB 3.01 KB NODE_DEV
react-dom-unstable-flight-client.development.js 0.0% 0.0% 8.53 KB 8.53 KB 2.54 KB 2.55 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 56.2 KB 56.2 KB 15.55 KB 15.55 KB UMD_DEV
react-dom-unstable-flight-client.production.min.js 0.0% 🔺+0.1% 2.71 KB 2.71 KB 1.27 KB 1.27 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% -0.0% 11.17 KB 11.17 KB 4.14 KB 4.14 KB UMD_PROD
react-dom-test-utils.production.min.js 0.0% -0.1% 10.94 KB 10.94 KB 4.08 KB 4.08 KB NODE_PROD

react-interactions

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-interactions-events/focus.production.min.js 🔺+3.7% 🔺+3.7% 4.37 KB 4.53 KB 1.43 KB 1.49 KB NODE_PROD
react-interactions-events/input.development.js 0.0% +0.1% 4.52 KB 4.52 KB 1.44 KB 1.44 KB UMD_DEV
react-interactions-events/press-legacy.production.min.js 0.0% 0.0% 7.22 KB 7.22 KB 2.74 KB 2.74 KB NODE_PROD
react-interactions-events/swipe.development.js 0.0% +0.1% 6 KB 6 KB 1.62 KB 1.63 KB UMD_DEV
react-interactions-events/input.production.min.js 0.0% 🔺+0.1% 1.84 KB 1.84 KB 983 B 984 B UMD_PROD
react-interactions-events/swipe.production.min.js 0.0% 🔺+0.1% 2.45 KB 2.45 KB 1.1 KB 1.11 KB UMD_PROD
react-interactions-events/hover.development.js 0.0% +0.1% 6.82 KB 6.82 KB 1.51 KB 1.51 KB NODE_DEV
react-interactions-events/scroll.development.js 0.0% +0.1% 6.12 KB 6.12 KB 1.61 KB 1.61 KB NODE_DEV
react-interactions-events/context-menu.development.js 0.0% +0.1% 2.68 KB 2.68 KB 1006 B 1007 B UMD_DEV
react-interactions-events/hover.production.min.js 0.0% 🔺+0.1% 2.94 KB 2.94 KB 1.07 KB 1.07 KB NODE_PROD
react-interactions-events/scroll.production.min.js 0.0% 🔺+0.1% 2.44 KB 2.44 KB 1.09 KB 1.09 KB NODE_PROD
react-interactions-events/context-menu.production.min.js 0.0% 🔺+0.1% 1.39 KB 1.39 KB 728 B 729 B UMD_PROD
react-interactions-events/keyboard.production.min.js 0.0% 🔺+0.1% 2.39 KB 2.39 KB 1.21 KB 1.21 KB UMD_PROD
react-interactions-events/context-menu.development.js 0.0% +0.1% 2.49 KB 2.49 KB 960 B 961 B NODE_DEV
react-interactions-events/keyboard.development.js 0.0% 0.0% 5.79 KB 5.79 KB 2.19 KB 2.19 KB NODE_DEV
react-interactions-events/focus.development.js +3.8% +2.2% 12.6 KB 13.07 KB 2.64 KB 2.7 KB UMD_DEV
react-interactions-events/press-legacy.development.js 0.0% 0.0% 24.52 KB 24.52 KB 6.1 KB 6.1 KB UMD_DEV
react-interactions-events/focus.production.min.js 🔺+3.6% 🔺+3.8% 4.54 KB 4.7 KB 1.5 KB 1.55 KB UMD_PROD
react-interactions-events/press-legacy.production.min.js 0.0% 0.0% 7.41 KB 7.41 KB 2.8 KB 2.8 KB UMD_PROD
react-interactions-events/focus.development.js +3.8% +2.2% 12.41 KB 12.89 KB 2.6 KB 2.65 KB NODE_DEV
react-interactions-events/input.development.js 0.0% +0.1% 4.34 KB 4.34 KB 1.4 KB 1.4 KB NODE_DEV
react-interactions-events/swipe.development.js 0.0% +0.1% 5.82 KB 5.82 KB 1.58 KB 1.58 KB NODE_DEV
react-interactions-events/drag.development.js 0.0% +0.1% 5.23 KB 5.23 KB 1.54 KB 1.54 KB UMD_DEV
react-interactions-events/input.production.min.js 0.0% 🔺+0.1% 1.66 KB 1.66 KB 916 B 917 B NODE_PROD
react-interactions-events/swipe.production.min.js 0.0% 🔺+0.1% 2.27 KB 2.27 KB 1.05 KB 1.05 KB NODE_PROD
react-interactions-events/press.production.min.js 0.0% 🔺+0.1% 2.65 KB 2.65 KB 1.09 KB 1.1 KB UMD_PROD
react-interactions-events/hover.development.js 0.0% +0.1% 7 KB 7 KB 1.55 KB 1.56 KB UMD_DEV
react-interactions-events/press.production.min.js 0.0% 🔺+0.1% 2.36 KB 2.36 KB 1.01 KB 1.01 KB NODE_PROD
react-interactions-events/scroll.development.js 0.0% +0.1% 6.3 KB 6.3 KB 1.65 KB 1.65 KB UMD_DEV
react-interactions-events/hover.production.min.js 0.0% 🔺+0.1% 3.12 KB 3.12 KB 1.13 KB 1.13 KB UMD_PROD
react-interactions-events/scroll.production.min.js 0.0% 🔺+0.1% 2.63 KB 2.63 KB 1.15 KB 1.15 KB UMD_PROD

Size changes (stable)

Generated by 🚫 dangerJS against eb5ba18

@sizebot
Copy link

sizebot commented Nov 13, 2019

Details of bundled changes.

Comparing: b53ea6c...eb5ba18

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% 0.0% 123.62 KB 123.65 KB 38.8 KB 38.82 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 20.39 KB 20.39 KB 7.48 KB 7.48 KB UMD_PROD
react-dom-unstable-flight-server.browser.production.min.js 0.0% 🔺+0.1% 2.85 KB 2.85 KB 1.33 KB 1.33 KB UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.88 KB 3.88 KB 1.55 KB 1.55 KB UMD_DEV
react-dom-unstable-flight-client.development.js 0.0% 0.0% 8.72 KB 8.72 KB 2.59 KB 2.6 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 11.18 KB 11.18 KB 4.15 KB 4.15 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.21 KB 1.21 KB 709 B 710 B UMD_PROD
ReactDOMServer-prod.js 0.0% 0.0% 48.79 KB 48.79 KB 11.13 KB 11.13 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-unstable-flight-client.development.js 0.0% 0.0% 8.54 KB 8.54 KB 2.55 KB 2.55 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 10.95 KB 10.95 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.05 KB 1.05 KB 640 B 641 B NODE_PROD
react-dom-unstable-flight-client.production.min.js 0.0% 🔺+0.1% 2.72 KB 2.72 KB 1.28 KB 1.28 KB NODE_PROD
react-dom.development.js +0.1% +0.1% 953.17 KB 953.81 KB 215.46 KB 215.61 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 119.65 KB 119.67 KB 38.42 KB 38.42 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 123.33 KB 123.35 KB 39.48 KB 39.5 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 947.28 KB 947.92 KB 213.89 KB 214.05 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 119.82 KB 119.84 KB 37.76 KB 37.77 KB NODE_PROD
react-dom-unstable-flight-server.browser.production.min.js 0.0% 🔺+0.1% 2.65 KB 2.65 KB 1.26 KB 1.26 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.14 KB 60.14 KB 15.79 KB 15.8 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.73 KB 10.73 KB 3.67 KB 3.67 KB UMD_PROD
ReactDOM-dev.js +0.1% +0.1% 975.38 KB 976.01 KB 216.44 KB 216.56 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 🔺+0.1% 402.55 KB 402.83 KB 73.14 KB 73.24 KB FB_WWW_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
ReactDOM-profiling.js +0.1% +0.1% 403.47 KB 403.75 KB 73.71 KB 73.78 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.48 KB 10.48 KB 3.57 KB 3.57 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.1% 1.21 KB 1.21 KB 696 B 697 B NODE_PROD

react-interactions

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-interactions-events/hover.development.js 0.0% +0.1% 7.02 KB 7.02 KB 1.56 KB 1.56 KB UMD_DEV
react-interactions-events/press-legacy.development.js 0.0% 0.0% 24.53 KB 24.53 KB 6.11 KB 6.11 KB UMD_DEV
react-interactions-events/press-legacy.production.min.js 0.0% 0.0% 7.42 KB 7.42 KB 2.81 KB 2.81 KB UMD_PROD
react-interactions-events/drag.development.js 0.0% +0.1% 5.24 KB 5.24 KB 1.55 KB 1.55 KB UMD_DEV
react-interactions-events/swipe.development.js 0.0% +0.1% 6.01 KB 6.01 KB 1.63 KB 1.63 KB UMD_DEV
react-interactions-events/keyboard.production.min.js 0.0% 🔺+0.1% 2.41 KB 2.41 KB 1.22 KB 1.22 KB UMD_PROD
react-interactions-events/swipe.production.min.js 0.0% 🔺+0.1% 2.46 KB 2.46 KB 1.11 KB 1.11 KB UMD_PROD
react-interactions-events/drag.development.js 0.0% -0.0% 7 KB 7 KB 2.22 KB 2.22 KB NODE_DEV
react-interactions-events/keyboard.development.js 0.0% +0.1% 5.8 KB 5.8 KB 2.2 KB 2.2 KB NODE_DEV
react-interactions-events/swipe.development.js 0.0% +0.1% 5.83 KB 5.83 KB 1.59 KB 1.59 KB NODE_DEV
react-interactions-events/drag.production.min.js 0.0% 🔺+0.1% 2.9 KB 2.9 KB 1.39 KB 1.39 KB NODE_PROD
react-interactions-events/swipe.production.min.js 0.0% 🔺+0.1% 2.28 KB 2.28 KB 1.06 KB 1.06 KB NODE_PROD
react-interactions-events/context-menu.development.js 0.0% +0.1% 2.69 KB 2.69 KB 1012 B 1013 B UMD_DEV
react-interactions-events/context-menu.production.min.js 0.0% 🔺+0.1% 1.4 KB 1.4 KB 736 B 737 B UMD_PROD
react-interactions-events/scroll.production.min.js 0.0% 🔺+0.1% 2.64 KB 2.64 KB 1.16 KB 1.16 KB UMD_PROD
ReactEventsFocus-dev.js +5.2% +3.5% 12.46 KB 13.11 KB 2.63 KB 2.72 KB FB_WWW_DEV
react-interactions-events/context-menu.development.js 0.0% +0.1% 2.5 KB 2.5 KB 968 B 969 B NODE_DEV
ReactEventsFocus-prod.js 🔺+8.2% 🔺+6.6% 9.07 KB 9.82 KB 1.85 KB 1.98 KB FB_WWW_PROD
react-interactions-events/input.development.js 0.0% +0.1% 4.35 KB 4.35 KB 1.4 KB 1.41 KB NODE_DEV
react-interactions-events/input.production.min.js 0.0% 🔺+0.1% 1.67 KB 1.67 KB 925 B 926 B NODE_PROD
react-interactions-events/scroll.production.min.js 0.0% 🔺+0.1% 2.46 KB 2.46 KB 1.1 KB 1.1 KB NODE_PROD
react-interactions-events/press-legacy.production.min.js 0.0% 0.0% 7.24 KB 7.24 KB 2.75 KB 2.75 KB NODE_PROD
react-interactions-events/focus.development.js +3.8% +2.2% 12.61 KB 13.09 KB 2.65 KB 2.71 KB UMD_DEV
react-interactions-events/focus.production.min.js 🔺+3.6% 🔺+3.7% 4.55 KB 4.71 KB 1.5 KB 1.56 KB UMD_PROD
react-interactions-events/press.production.min.js 0.0% 🔺+0.1% 2.66 KB 2.66 KB 1.1 KB 1.1 KB UMD_PROD
react-interactions-events/focus.development.js +3.8% +2.2% 12.43 KB 12.9 KB 2.6 KB 2.66 KB NODE_DEV
react-interactions-events/press.development.js 0.0% 0.0% 8.79 KB 8.79 KB 2.59 KB 2.59 KB NODE_DEV
react-interactions-events/focus.production.min.js 🔺+3.7% 🔺+3.7% 4.38 KB 4.54 KB 1.44 KB 1.5 KB NODE_PROD
react-interactions-events/press.production.min.js 0.0% 🔺+0.1% 2.37 KB 2.37 KB 1.02 KB 1.02 KB NODE_PROD
react-interactions-events/tap.production.min.js 0.0% 0.0% 6.16 KB 6.16 KB 2.33 KB 2.33 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against eb5ba18

Copy link

@tatermelon tatermelon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!!

remove debugger

Add beforeRemoveInstance

fix typi
Copy link
Contributor

@necolas necolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the names need to be changed, as every blur event occurs on the activeElement. I suggest something like onFocusedElementDetached and onBeforeFocusedElementDetached.

An alternative approach might be not to use dedicated events and instead overload the blur events with additional meta-information, but this was not deemed a desirable approach internally because other event responders that listen to blur also need to know about this additional meta-information.

I don't understand this reasoning. Which event responders listening to blur would this impact? How does a new event avoid the issues?

packages/react-interactions/events/src/dom/Focus.js Outdated Show resolved Hide resolved
@trueadm
Copy link
Contributor Author

trueadm commented Nov 13, 2019

@necolas Thanks. I've addressed all your feedback :)

Copy link
Contributor

@necolas necolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but needs more name updates

Fix typo

remove dead code

prettier
@trueadm trueadm merged commit a61886b into facebook:master Nov 13, 2019
@trueadm trueadm deleted the add-another-event branch November 13, 2019 20:46
Copy link
Contributor

@necolas necolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this code now dispatches 2 blur events when an element is removed. It's not quite what I was suggesting; I added inline comments related to renaming things and the events that get dispatched. LMK what you think

@@ -104,6 +104,12 @@ export type ChildSet = void; // Unused
export type TimeoutHandle = TimeoutID;
export type NoTimeout = -1;

type SelectionInformation = {|
blurredActiveElement: null | HTMLElement,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
blurredActiveElement: null | HTMLElement,
detachedActiveElement: null | HTMLElement,


type FocusWithinProps = {
disabled?: boolean,
onFocusWithin?: (e: FocusEvent) => void,
onBlurWithin?: (e: FocusEvent) => void,
onFocusWithinChange?: boolean => void,
onFocusWithinVisibleChange?: boolean => void,
onDetachedVisibleNode?: (e: FocusEvent) => void,
onBeforeFocusedElementDetached?: (e: FocusEvent) => void,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onBeforeBlurWithin, only called when the element is going to be removed from the document


type FocusWithinProps = {
disabled?: boolean,
onFocusWithin?: (e: FocusEvent) => void,
onBlurWithin?: (e: FocusEvent) => void,
onFocusWithinChange?: boolean => void,
onFocusWithinVisibleChange?: boolean => void,
onDetachedVisibleNode?: (e: FocusEvent) => void,
onBeforeFocusedElementDetached?: (e: FocusEvent) => void,
onFocusedElementDetached?: (e: FocusEvent) => void,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't be needed, onBlurWithin payload can include the elementAttached data

Comment on lines +65 to +66
| 'focusedelementdetached'
| 'beforefocusedelementdetached';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with beforeblurwithin

Comment on lines +487 to +491
function dispatchBeforeActiveElementBlur(element: HTMLElement): void {
const targtInstance = getClosestInstanceFromNode(element);
((selectionInformation: any): SelectionInformation).blurredActiveElement = element;
dispatchFlareDetachedBlurEvent(false, targtInstance, element);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function dispatchBeforeActiveElementBlur(element: HTMLElement): void {
const targtInstance = getClosestInstanceFromNode(element);
((selectionInformation: any): SelectionInformation).blurredActiveElement = element;
dispatchFlareDetachedBlurEvent(false, targtInstance, element);
}
function dispatchBeforeDetachedBlur(target: HTMLElement): void {
const targtInstance = getClosestInstanceFromNode(element);
selectionInformation.detachedActiveElement = target;
dispatchEventForResponderEventSystem(
'beforeblur',
targetInstance,
({
target,
timeStamp: Date.now(),
}: any),
target,
RESPONDER_EVENT_SYSTEM | IS_PASSIVE,
);

Comment on lines +215 to +219
const blurredActiveElement = (selectionInformation: any)
.blurredActiveElement;
if (blurredActiveElement !== null) {
dispatchActiveElementBlur(blurredActiveElement);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const blurredActiveElement = (selectionInformation: any)
.blurredActiveElement;
if (blurredActiveElement !== null) {
dispatchActiveElementBlur(blurredActiveElement);
}
const activeElementDetached = (selectionInformation: any).activeElementDetached;
if (activeElementDetached !== null) {
dispatchDetachedBlur(activeElementDetached);
}

Comment on lines +493 to +497
function dispatchActiveElementBlur(
node: Instance | TextInstance | SuspenseInstance,
): void {
dispatchFlareDetachedBlurEvent(true, null, ((node: any): HTMLElement));
}
Copy link
Contributor

@necolas necolas Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function dispatchActiveElementBlur(
node: Instance | TextInstance | SuspenseInstance,
): void {
dispatchFlareDetachedBlurEvent(true, null, ((node: any): HTMLElement));
}
function dispatchDetachedBlur(target) {
const targtInstance = getClosestInstanceFromNode(target);
dispatchEventForResponderEventSystem(
'blur',
targetInstance,
({
isTargetAttached: false,
target,
timeStamp: Date.now(),
}: any),
target,
RESPONDER_EVENT_SYSTEM | IS_PASSIVE,
);

((child: any): Document | Element),
RESPONDER_EVENT_SYSTEM | IS_PASSIVE,
);
dispatchBeforeActiveElementBlur(((instance: any): HTMLElement));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dispatchBeforeActiveElementBlur(((instance: any): HTMLElement));
dispatchBeforeDetachedBlur(((instance: any): HTMLElement));

@@ -100,6 +100,8 @@ export function hasSelectionCapabilities(elem) {
export function getSelectionInformation() {
const focusedElem = getActiveElementDeep();
return {
// Used by Flare
blurredActiveElement: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
blurredActiveElement: null,
activeElementDetached: null,

@trueadm
Copy link
Contributor Author

trueadm commented Nov 13, 2019

Thanks for the feedback @necolas. Those changes look good, I'll address tomorrow in a follow up PR.

Update: #17364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants