3
3
* This package is experimental. It is intended for use with the experimental React
4
4
events API that is not available in open source builds.*
5
5
6
+ Event components do not render a host node. They listen to native browser events
7
+ dispatched on the host node of their child and transform those events into
8
+ high-level events for applications.
9
+
6
10
7
11
## Focus
8
12
9
13
The ` Focus ` module responds to focus and blur events on the element it wraps.
10
14
Focus events are dispatched for ` mouse ` , ` pen ` , ` touch ` , and ` keyboard `
11
15
pointer types.
12
16
17
+ ``` js
18
+ // Example
19
+ const TextField = (props ) => (
20
+ < Focus
21
+ onBlur= {props .onBlur }
22
+ onFocus= {props .onFocus }
23
+ >
24
+ < textarea>< / textarea>
25
+ < / Focus>
26
+ );
13
27
```
28
+
29
+ ``` js
30
+ // Types
14
31
type FocusEvent = {}
15
32
```
16
33
@@ -38,69 +55,124 @@ The `Hover` module responds to hover events on the element it wraps. Hover
38
55
events are only dispatched for ` mouse ` pointer types. Hover begins when the
39
56
pointer enters the element's bounds and ends when the pointer leaves.
40
57
58
+ ``` js
59
+ // Example
60
+ const Link = (props ) => (
61
+ const [ hovered , setHovered ] = useState (false );
62
+ return (
63
+ < Hover onHoverChange= {setHovered}>
64
+ < a
65
+ {... props}
66
+ href= {props .href }
67
+ style= {{
68
+ ... props .style ,
69
+ textDecoration: hovered ? ' underline' : ' none'
70
+ }}
71
+ / >
72
+ < / Hover>
73
+ );
74
+ );
41
75
```
76
+
77
+ ``` js
78
+ // Types
42
79
type HoverEvent = {}
43
80
```
44
81
45
- ### disabled: boolean
82
+ ### delayHoverEnd: number
46
83
47
- Disables all ` Hover ` events.
84
+ The duration of the delay between when hover ends and when ` onHoverEnd ` is
85
+ called.
48
86
49
- ### onHoverStart: (e: HoverEvent) => void
87
+ ### delayHoverStart: number
50
88
51
- Called once the element is hovered. It will not be called if the pointer leaves
52
- the element before the ` delayHoverStart ` threshold is exceeded. And it will not
53
- be called more than once before ` onHoverEnd ` is called.
89
+ The duration of the delay between when hover starts and when ` onHoverStart ` is
90
+ called.
54
91
55
- ### onHoverEnd: (e: HoverEvent) => void
92
+ ### disabled: boolean
56
93
57
- Called once the element is no longer hovered. It will be cancelled if the
58
- pointer leaves the element before the ` delayHoverStart ` threshold is exceeded.
94
+ Disables all ` Hover ` events.
59
95
60
96
### onHoverChange: boolean => void
61
97
62
98
Called when the element changes hover state (i.e., after ` onHoverStart ` and
63
99
` onHoverEnd ` ).
64
100
65
- ### delayHoverStart: number
101
+ ### onHoverEnd: (e: HoverEvent) => void
66
102
67
- The duration of the delay between when hover starts and when ` onHoverStart ` is
68
- called .
103
+ Called once the element is no longer hovered. It will be cancelled if the
104
+ pointer leaves the element before the ` delayHoverStart ` threshold is exceeded .
69
105
70
- ### delayHoverEnd: number
106
+ ### onHoverStart: (e: HoverEvent) => void
71
107
72
- The duration of the delay between when hover ends and when ` onHoverEnd ` is
73
- called.
108
+ Called once the element is hovered. It will not be called if the pointer leaves
109
+ the element before the ` delayHoverStart ` threshold is exceeded. And it will not
110
+ be called more than once before ` onHoverEnd ` is called.
74
111
75
112
76
113
## Press
77
114
78
115
The ` Press ` module responds to press events on the element it wraps. Press
79
116
events are dispatched for ` mouse ` , ` pen ` , ` touch ` , and ` keyboard ` pointer types.
80
-
117
+ Press events are only dispatched for keyboards when pressing the Enter or
118
+ Spacebar keys. If neither ` onPress ` nor ` onLongPress ` are called, this signifies
119
+ that the press ended outside of the element hit bounds (i.e., the user aborted
120
+ the press).
121
+
122
+ ``` js
123
+ // Example
124
+ const Button = (props ) => (
125
+ const [ pressed , setPressed ] = useState (false );
126
+ return (
127
+ < Press
128
+ onPress= {props .onPress }
129
+ onPressChange= {setPressed}
130
+ onLongPress= {props .onLongPress }
131
+ >
132
+ < div
133
+ {... props}
134
+ role= " button"
135
+ tabIndex= {0 }
136
+ style= {
137
+ ... buttonStyles,
138
+ ... (pressed && pressedStyles)
139
+ }}
140
+ / >
141
+ < / Press>
142
+ );
143
+ );
81
144
```
145
+
146
+ ``` js
147
+ // Types
82
148
type PressEvent = {}
149
+
150
+ type PressOffset = {
151
+ top: number,
152
+ right: number,
153
+ bottom: number,
154
+ right: number
155
+ };
83
156
```
84
157
85
- ### disabled: boolean
158
+ ### delayLongPress: number = 500ms
86
159
87
- Disables all ` Press ` events .
160
+ The duration of a press before ` onLongPress ` and ` onLongPressChange ` are called .
88
161
89
- ### onPressStart: (e: PressEvent) => void
162
+ ### delayPressEnd: number
90
163
91
- Called once the element is pressed down. If the press is released before the
92
- ` delayPressStart ` threshold is exceeded then the delay is cut short and
93
- ` onPressStart ` is called immediately.
164
+ The duration of the delay between when the press ends and when ` onPressEnd ` is
165
+ called.
94
166
95
- ### onPressEnd: (e: PressEvent) => void
167
+ ### delayPressStart: number
96
168
97
- Called once the element is no longer pressed. It will be cancelled if the press
98
- starts again before the ` delayPressEnd ` threshold is exceeded.
169
+ The duration of a delay between when the press starts and when ` onPressStart ` is
170
+ called. This delay is cut short (and ` onPressStart ` is called) if the press is
171
+ released before the threshold is exceeded.
99
172
100
- ### onPressChange : boolean => void
173
+ ### disabled : boolean
101
174
102
- Called when the element changes press state (i.e., after ` onPressStart ` and
103
- ` onPressEnd ` ).
175
+ Disables all ` Press ` events.
104
176
105
177
### onLongPress: (e: PressEvent) => void
106
178
@@ -117,25 +189,30 @@ Determines whether calling `onPress` should be cancelled if `onLongPress` or
117
189
118
190
### onPress: (e: PressEvent) => void
119
191
120
- Called after ` onPressEnd ` only if ` onLongPressShouldCancelPress ` returns
121
- ` false ` .
192
+ Called immediately after a press is released, unless either 1) the press is
193
+ released outside the hit bounds of the element (accounting for
194
+ ` pressRetentionOffset ` and ` TouchHitTarget ` ), or 2) the press was a long press,
195
+ and ` onLongPress ` or ` onLongPressChange ` props are provided, and
196
+ ` onLongPressCancelsPress() ` is ` true ` .
122
197
123
- ### delayPressStart: number
198
+ ### onPressChange: boolean => void
124
199
125
- The duration of a delay between when the press starts and when ` onPressStart ` is
126
- called. This delay is cut short if the press ends released before the threshold
127
- is exceeded.
200
+ Called when the element changes press state (i.e., after ` onPressStart ` and
201
+ ` onPressEnd ` ).
128
202
129
- ### delayPressEnd: number
203
+ ### onPressEnd: (e: PressEvent) => void
130
204
131
- The duration of the delay between when the press ends and when ` onPressEnd ` is
132
- called.
205
+ Called once the element is no longer pressed. If the press starts again before
206
+ the ` delayPressEnd ` threshold is exceeded then the delay is reset to prevent
207
+ ` onPressEnd ` being called during a press.
133
208
134
- ### delayLongPress: number = 500ms
209
+ ### onPressStart: (e: PressEvent) => void
135
210
136
- The duration of a press before ` onLongPress ` and ` onLongPressChange ` are called.
211
+ Called once the element is pressed down. If the press is released before the
212
+ ` delayPressStart ` threshold is exceeded then the delay is cut short and
213
+ ` onPressStart ` is called immediately.
137
214
138
- ### pressRententionOffset: { top: number, right: number, bottom: number, right: number }
215
+ ### pressRententionOffset: PressOffset
139
216
140
217
Defines how far the pointer (while held down) may move outside the bounds of the
141
218
element before it is deactivated. Once deactivated, the pointer (still held
0 commit comments