Skip to content

Commit

Permalink
[Flare] Add FocusWithin responder (#16152)
Browse files Browse the repository at this point in the history
FocusWithin is implemented as a separate responder, which keeps both focus
responders simple and allows for easier composition of behaviours.
  • Loading branch information
necolas committed Jul 17, 2019
1 parent 65b80fd commit 997154b
Show file tree
Hide file tree
Showing 3 changed files with 676 additions and 173 deletions.
57 changes: 57 additions & 0 deletions packages/react-events/docs/FocusWithin.md
@@ -0,0 +1,57 @@
# FocusWithin

The `FocusWithin` module responds to focus and blur events on its child. Focus events
are dispatched for all input types, with the exception of `onFocusVisibleChange`
which is only dispatched when focusing with a keyboard.

Focus events do not propagate between `FocusWithin` event responders.

```js
// Example
const Button = (props) => {
const [ focusWithin, updateFocusWithin ] = useState(false);
const [ focusWithinVisible, updateFocusWithinVisible ] = useState(false);

return (
<FocusWithin
onFocusWithinChange={updateFocusWithin}
onFocusWithinVisibleChange={updateFocusWithinVisible}
>
<button
children={props.children}
style={{
...(focusWithin && focusWithinStyles),
...(focusWithinVisible && focusWithinVisibleStyles)
}}
>
</FocusWithin>
);
};
```

## Types

```js
type FocusEvent = {
target: Element,
type: 'focuswithinchange' | 'focuswithinvisiblechange'
}
```

## Props

### disabled: boolean = false

Disables all `FocusWithin` events.

### onFocusWithinChange: boolean => void

Called once the element or a descendant receives focus, and once focus moves
outside of the element.

### onFocusWithinVisibleChange: boolean => void

Called once the element or a descendant is focused following keyboard
navigation, and once focus moves outside of the element. This can be used to
display focus styles only when the keyboard is being used to focus within the
element's subtree.

0 comments on commit 997154b

Please sign in to comment.