|
1 | 1 | # FocusWithin |
2 | 2 |
|
3 | | -The `FocusWithin` module responds to focus and blur events on its child. Focus events |
| 3 | +The `useFocusWithin` hooks responds to focus and blur events on its child. Focus events |
4 | 4 | are dispatched for all input types, with the exception of `onFocusVisibleChange` |
5 | 5 | which is only dispatched when focusing with a keyboard. |
6 | 6 |
|
7 | | -Focus events do not propagate between `FocusWithin` event responders. |
| 7 | +Focus events do not propagate between `useFocusWithin` event responders. |
8 | 8 |
|
9 | 9 | ```js |
10 | 10 | // Example |
11 | 11 | const Button = (props) => { |
12 | | - const [ focusWithin, updateFocusWithin ] = useState(false); |
13 | | - const [ focusWithinVisible, updateFocusWithinVisible ] = useState(false); |
| 12 | + const [ isFocusWithin, updateFocusWithin ] = useState(false); |
| 13 | + const [ isFocusWithinVisible, updateFocusWithinVisible ] = useState(false); |
| 14 | + const focusWithin = useFocusWithin({ |
| 15 | + onFocusWithinChange={updateFocusWithin} |
| 16 | + onFocusWithinVisibleChange={updateFocusWithinVisible} |
| 17 | + }); |
14 | 18 |
|
15 | 19 | return ( |
16 | | - <FocusWithin |
17 | | - onFocusWithinChange={updateFocusWithin} |
18 | | - onFocusWithinVisibleChange={updateFocusWithinVisible} |
| 20 | + <button |
| 21 | + children={props.children} |
| 22 | + listeners={focusWithin} |
| 23 | + style={{ |
| 24 | + ...(isFocusWithin && focusWithinStyles), |
| 25 | + ...(isFocusWithinVisible && focusWithinVisibleStyles) |
| 26 | + }} |
19 | 27 | > |
20 | | - <button |
21 | | - children={props.children} |
22 | | - style={{ |
23 | | - ...(focusWithin && focusWithinStyles), |
24 | | - ...(focusWithinVisible && focusWithinVisibleStyles) |
25 | | - }} |
26 | | - > |
27 | | - </FocusWithin> |
28 | 28 | ); |
29 | 29 | }; |
30 | 30 | ``` |
31 | 31 |
|
32 | | -## Types |
33 | | - |
34 | | -```js |
35 | | -type FocusEvent = { |
36 | | - target: Element, |
37 | | - type: 'focuswithinchange' | 'focuswithinvisiblechange' |
38 | | -} |
39 | | -``` |
40 | | - |
41 | 32 | ## Props |
42 | 33 |
|
43 | 34 | ### disabled: boolean = false |
44 | 35 |
|
45 | | -Disables all `FocusWithin` events. |
| 36 | +Disables the responder. |
46 | 37 |
|
47 | 38 | ### onFocusWithinChange: boolean => void |
48 | 39 |
|
|
0 commit comments