File tree Expand file tree Collapse file tree 3 files changed +676
-173
lines changed Expand file tree Collapse file tree 3 files changed +676
-173
lines changed Original file line number Diff line number Diff line change 1+ # FocusWithin
2+
3+ The ` FocusWithin ` module responds to focus and blur events on its child. Focus events
4+ are dispatched for all input types, with the exception of ` onFocusVisibleChange `
5+ which is only dispatched when focusing with a keyboard.
6+
7+ Focus events do not propagate between ` FocusWithin ` event responders.
8+
9+ ``` js
10+ // Example
11+ const Button = (props ) => {
12+ const [ focusWithin , updateFocusWithin ] = useState (false );
13+ const [ focusWithinVisible , updateFocusWithinVisible ] = useState (false );
14+
15+ return (
16+ < FocusWithin
17+ onFocusWithinChange= {updateFocusWithin}
18+ onFocusWithinVisibleChange= {updateFocusWithinVisible}
19+ >
20+ < button
21+ children= {props .children }
22+ style= {{
23+ ... (focusWithin && focusWithinStyles),
24+ ... (focusWithinVisible && focusWithinVisibleStyles)
25+ }}
26+ >
27+ < / FocusWithin>
28+ );
29+ };
30+ ```
31+
32+ ## Types
33+
34+ ``` js
35+ type FocusEvent = {
36+ target: Element ,
37+ type: ' focuswithinchange' | ' focuswithinvisiblechange'
38+ }
39+ ```
40+
41+ ## Props
42+
43+ ### disabled: boolean = false
44+
45+ Disables all ` FocusWithin ` events.
46+
47+ ### onFocusWithinChange: boolean => void
48+
49+ Called once the element or a descendant receives focus, and once focus moves
50+ outside of the element.
51+
52+ ### onFocusWithinVisibleChange: boolean => void
53+
54+ Called once the element or a descendant is focused following keyboard
55+ navigation, and once focus moves outside of the element. This can be used to
56+ display focus styles only when the keyboard is being used to focus within the
57+ element's subtree.
You can’t perform that action at this time.
0 commit comments