picker icon indicating copy to clipboard operation
picker copied to clipboard

Cannot trigger focus using ref

Open aaronvega-msft opened this issue 3 years ago • 4 comments

    dropdownRef: React.RefObject<Picker<string>>;
    textBoxRef: React.RefObject<TextInput>;

    constructor(props: any) {
        super(props);
        this.dropdownRef = React.createRef();
        this.textBoxRef = React.createRef();
    }

    async componentDidMount() {
        setTimeout(() => {
            this.dropdownRef.current?.focus();

            setTimeout(() => {
                this.textBoxRef.current?.focus();
            }, 3000);

        }, 3000);
    }

    render() {
        return <View>
            <View >
                <View >
                    <Picker
                        ref={this.dropdownRef}
                    >
                        <Picker.Item label={"Apples"} value={1} key={1} />
                        <Picker.Item label={"Oranges"} value={2} key={2} />
                    </Picker>
                </View>
                <View>
                    <TextInput
                        ref={this.textBoxRef}
                    />
                </View>
            </View>
        </View>
    }   

Focus does not land on picker when its ref gets called in componentDidMount. Is there a fix for this?

Using:

  • react-native-picker/picker: 2.4.1
  • react-native: 0.67.4
  • react-native-windows: 0.67.8
  • Platform: Windows 10/11

aaronvega-msft avatar Jun 10 '22 22:06 aaronvega-msft

Its currently only available for Android ... no idea why. This definitely needs to be fixed though.

josh-thompson13 avatar Mar 01 '23 00:03 josh-thompson13