File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
packages/react-native-web/src/exports/Pressable Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,25 @@ describe('components/Pressable', () => {
91
91
expect ( container . firstChild ) . toMatchSnapshot ( ) ;
92
92
} ) ;
93
93
94
+ test ( 'focus interaction (disabled)' , ( ) => {
95
+ const onBlur = jest . fn ( ) ;
96
+ const onFocus = jest . fn ( ) ;
97
+ const ref = React . createRef ( ) ;
98
+ act ( ( ) => {
99
+ render ( < Pressable disabled = { true } onBlur = { onBlur } onFocus = { onFocus } ref = { ref } /> ) ;
100
+ } ) ;
101
+ const target = createEventTarget ( ref . current ) ;
102
+ const body = createEventTarget ( document . body ) ;
103
+ act ( ( ) => {
104
+ target . focus ( ) ;
105
+ } ) ;
106
+ expect ( onFocus ) . not . toBeCalled ( ) ;
107
+ act ( ( ) => {
108
+ body . focus ( { relatedTarget : target . node } ) ;
109
+ } ) ;
110
+ expect ( onBlur ) . not . toBeCalled ( ) ;
111
+ } ) ;
112
+
94
113
test ( 'hover interaction' , ( ) => {
95
114
let container ;
96
115
const onHoverIn = jest . fn ( ) ;
Original file line number Diff line number Diff line change @@ -144,26 +144,32 @@ function Pressable(props: Props, forwardedRef): React.Node {
144
144
145
145
const blurHandler = React . useCallback (
146
146
( e ) => {
147
+ if ( disabled ) {
148
+ return ;
149
+ }
147
150
if ( e . nativeEvent . target === hostRef . current ) {
148
151
setFocused ( false ) ;
149
152
if ( onBlur != null ) {
150
153
onBlur ( e ) ;
151
154
}
152
155
}
153
156
} ,
154
- [ hostRef , setFocused , onBlur ]
157
+ [ disabled , hostRef , setFocused , onBlur ]
155
158
) ;
156
159
157
160
const focusHandler = React . useCallback (
158
161
( e ) => {
162
+ if ( disabled ) {
163
+ return ;
164
+ }
159
165
if ( e . nativeEvent . target === hostRef . current ) {
160
166
setFocused ( true ) ;
161
167
if ( onFocus != null ) {
162
168
onFocus ( e ) ;
163
169
}
164
170
}
165
171
} ,
166
- [ hostRef , setFocused , onFocus ]
172
+ [ disabled , hostRef , setFocused , onFocus ]
167
173
) ;
168
174
169
175
const contextMenuHandler = React . useCallback (
You can’t perform that action at this time.
0 commit comments