Skip to content

Commit

Permalink
[react-interactions] Add onFocusWithin event to FocusWithin responder (
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Oct 16, 2019
1 parent d7feeb2 commit 9169375
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/react-interactions/events/src/dom/Focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type FocusEventType = 'focus' | 'blur' | 'focuschange' | 'focusvisiblechange';

type FocusWithinProps = {
disabled?: boolean,
onFocusWithin?: (e: FocusEvent) => void,
onBlurWithin?: (e: FocusEvent) => void,
onFocusWithinChange?: boolean => void,
onFocusWithinVisibleChange?: boolean => void,
Expand All @@ -57,7 +58,8 @@ type FocusWithinProps = {
type FocusWithinEventType =
| 'focuswithinvisiblechange'
| 'focuswithinchange'
| 'blurwithin';
| 'blurwithin'
| 'focuswithin';

/**
* Shared between Focus and FocusWithin
Expand Down Expand Up @@ -239,6 +241,26 @@ function dispatchBlurEvents(
}
}

function dispatchFocusWithinEvents(
context: ReactDOMResponderContext,
event: ReactDOMResponderEvent,
props: FocusWithinProps,
state: FocusState,
) {
const pointerType = state.pointerType;
const target = ((state.focusTarget: any): Element | Document) || event.target;
const onFocusWithin = (props.onFocusWithin: any);
if (isFunction(onFocusWithin)) {
const syntheticEvent = createFocusEvent(
context,
'focuswithin',
target,
pointerType,
);
context.dispatchEvent(syntheticEvent, onFocusWithin, DiscreteEvent);
}
}

function dispatchBlurWithinEvents(
context: ReactDOMResponderContext,
event: ReactDOMResponderEvent,
Expand Down Expand Up @@ -474,6 +496,7 @@ const focusWithinResponderImpl = {
state.isFocusVisible = isGlobalFocusVisible;
dispatchFocusWithinVisibleChangeEvent(context, props, state, true);
}
dispatchFocusWithinEvents(context, event, props, state);
break;
}
case 'blur': {
Expand Down

0 comments on commit 9169375

Please sign in to comment.