-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the issue
Clicking on a Pressable with disabled={true} does not trigger it to go into a focused state, however clicking on it's children does.
Expected behavior
If the Pressable is disabled, the same behavior should be applied to it's children elements and tapping them should not cause the pressable's onFocus event to fire.
Steps to reproduce
- Create a Pressable with a Text child
- Set its disabled state to
true, addonPress,onFocus,onBlurevents to toggle the focused state of the Pressable. - Notice that tapping the Pressable does nor fire
onPressoronFocusevents, since the button is disabled, however tapping the Text element firesonFocus
Test case
https://snack.expo.dev/@kristinetrona/tenacious-green-soda?platform=web
Additional comments
Example code:
import { Text, SafeAreaView, Pressable, StyleSheet } from 'react-native';
import { useState } from 'react';
export default function App() {
const [isDisabled, setIsDisabled] = useState(false)
const [isFocused, setIsFocused] = useState(false)
const onPress = () => {
console.log("Button pressed")
}
const onFocus = () => {
setIsFocused(true)
}
const onBlur = () => {
setIsFocused(false)
}
const onToggleDisabledState = () => {
setIsDisabled((prevState) => !prevState)
}
return (
<SafeAreaView style={styles.container}>
<Text style={styles.disabledText}>
{`isDisabled: ${isDisabled}`}
</Text>
<Pressable
style={[styles.button, isFocused && styles.focusedButton, isDisabled && styles.disabledButton]}
disabled={isDisabled}
onPress={onPress}
onFocus={onFocus}
onBlur={onBlur}>
<Text>{`Button isFocused: ${isFocused}`}</Text>
</Pressable>
<Pressable style={styles.disableToggleButton} onPress={onToggleDisabledState}>
<Text>Toggle disable</Text>
</Pressable>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
disabledText: {
marginBottom: 32,
},
button: {
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'pink',
padding: 8,
},
focusedButton: {
backgroundColor: 'orange',
},
disabledButton: {
backgroundColor: 'grey'
},
disableToggleButton: {
marginTop: 32,
padding: 8,
alignItems: 'center',
justifyContent: 'center',
borderColor: 'black',
borderWidth: 1
}
});