Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export the setSelection method on TextInput's ref #4603

Open
TivonJJ opened this issue Jan 15, 2025 · 0 comments
Open

Export the setSelection method on TextInput's ref #4603

TivonJJ opened this issue Jan 15, 2025 · 0 comments

Comments

@TivonJJ
Copy link

TivonJJ commented Jan 15, 2025

Issue

I wanna use TextInput ref to set user selection, The react native has setSelection method, But it's not work on react-native-paper.
I saw the source code it dosent export this method. (

React.useImperativeHandle(ref, () => ({
)

Example

import { View, TextInput } from 'react-native';

 const ReceiveScreen: ScreenPage<{ initialAmount?: number }> = ({ route: { params } }) => {
    const f = useRef<TextInput>(null);
    return (
        <Screen>
            <TextInput value={'Hi this is a input'} ref={f} />
            <Button
                onPress={() => {
                    f.current?.focus();
                    // The TextInput from 'react-native' is work fine, but it's undefined while from 'react-native-paper'
                    f.current?.setSelection(0, 3);
                }}
            >
                Select
            </Button>
        </Screen>
    );
};

💡 I have tried to use setNativeProps instead, but it's not work both on react-native and react-native-paper.
Currently, I am doing it by rewriting the render, I think it's better to export this usefull method.

@TivonJJ TivonJJ changed the title Export the setSelection method on ref Export the setSelection method on TextInput's ref Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant