Skip to content

Click and hold to select text using a text component #13938

Open

Description

@yasemincidem

Description

I want click-and-hold-to-select-text using a Text component and then i searched it and i found selectable property.It good works but it copy the entire text field.I want to selecting a subset of the text field for copying.Actually this question is asked on stackoverflow .Here is question on stackoverflow:http://stackoverflow.com/a/37119619/4596143

Reproduction Steps and Sample Code

I try this code block:

<Text
                        selectable={true}
                        style={styles.messageBody}>
                        {"text description"}
</Text>

This full of text ("text description") can copy not partially .I want to it like screenshot

Actual behaviour:
image

Expected behavior:

image

Solution

They are said that RN 0.39 adds support to copy the entire text field, but does not yet include support for selecting a subset of the text field for copying on stackoverflow .I wonder Text component include support for selecting a subset of the text field for copying on new versions for react native.If the property does not exist on new versions ,will the property for text integrate ?

Additional Information

  • React Native version:^0.43
  • Platform: IOS
  • Development Operating System: macOS

Activity

  1. fenglu09 commented on Apr 20, 2018

    @fenglu09

    @yasemincidem Have you found a solution?

  2. react-native-bot commented on May 7, 2018

    @react-native-bot
    Collaborator

    This issue looks like a question and not an actual bug report. Please try asking over on Stack Overflow instead.

  3. BichCNTT commented on May 9, 2018

    @BichCNTT

    Hello guys,
    How I can get the word selected when set selectable={true}
    Can you tell me?
    Ths.

  4. ethanleeX commented on Jun 14, 2018

    @ethanleeX
  5. wcandillon commented on Aug 2, 2018

    @wcandillon
    Contributor

    @react-native-bot this issue should be reopened

  6. singhsoldier13 commented on Aug 16, 2018

    @singhsoldier13

    +1

  7. thinhtrh commented on Sep 5, 2018

    @thinhtrh

    +1

  8. yusent commented on Sep 19, 2018

    @yusent

    +1

  9. ezrra commented on Sep 19, 2018

    @ezrra

    +1

  10. axelfrid commented on Oct 23, 2018

    @axelfrid

    +1

  11. j-ornelas commented on Nov 16, 2018

    @j-ornelas

    +1

  12. xinfang commented on Nov 27, 2018

    @xinfang

    +1

  13. mraak commented on Nov 27, 2018

    @mraak

    +1

  14. AbdelhalimAhmed commented on Nov 27, 2018

    @AbdelhalimAhmed

    +1

  15. jeongsd commented on Nov 28, 2018

    @jeongsd

    +1

  16. kala888 commented on Nov 29, 2018

    @kala888

    this issue should be reopened again

  17. kala888 commented on Nov 29, 2018

    @kala888

    Here is a temporary solution。

        {imageText.length > 0 &&
                    device.ios && (
                      <AutoGrowingTextInput
                        scrollEnabled={false}
                        value={`        ${imageText}`}
                        editable={false}
                      />
                    )}
    
                  {imageText.length > 0 &&
                    device.android && (
                      <Text selectable>
                        {'        '}
                        {imageText}
                      </Text>
                    )}
    
  18. msand commented on Dec 12, 2018

    @msand
    Contributor

    I've published a workaround for now if you're interested: https://github.com/msand/react-native-selectable-text

    It's only needed on Android, and works as a drop-in replacement for a TextInput with these specific values on iOS, as TextInput with editable: false already works correctly there. TextInput on Android either fills most of the screen with the keyboard, or disables the ability to select and respond to selection changes. I would assume this component only works well for the specific use-case I had, haven't tested it for any other prop values.

    import SelectableText from 'react-native-selectable-text';
    
    export default ({ text, onSelectionChange }) => (
      <SelectableText
        selectable
        multiline
        contextMenuHidden
        scrollEnabled={false}
        editable={false}
        onSelectionChange={onSelectionChange}
        style={{
          color: "#BAB6C8",
        }}
        value={text}
      />);
  19. zhouanbo commented on Dec 21, 2018

    @zhouanbo

    My solution is to use https://www.npmjs.com/package/react-native-webview-autoheight and load text as html.

  20. kkusanagi commented on May 28, 2019

    @kkusanagi

    React-Native 0.59 version. Only show COPY when long press.
    Edit: Seems only work for Android version. IOS don't have this feature.

  21. scarlac commented on Aug 12, 2019

    @scarlac
    Contributor

    Use a <TextInput/> on iOS to allow multiple actions and use a regular <Text/> on Android. That will allow specific word selection on both platforms. No linking. No native libraries. Just use this:

    import { Platform } from 'react-native';
    // ...
    {Platform.OS === 'ios' ? (
      // iOS requires a textinput for word selections
      <TextInput
        value={description}
        editable={false}
        multiline
      />
    ) : (
      // Android can do word selections just with <Text>
      <Text selectable>{description}</Text>
    )}

    Result, Android:
    image

    Result, iOS:
    image

  22. hoanvnbka commented on Aug 16, 2019

    @hoanvnbka

    I test version 0.59.10 but selectable did not work. Does anyone have same error?

  23. acro5piano commented on Nov 26, 2019

    @acro5piano

    @scarlac
    Thanks for the workaround. How do you treat nested <TextInput /> ? It seems to accept type of string.

  24. scarlac commented on Nov 26, 2019

    @scarlac
    Contributor

    @acro5piano TextInput cannot be nested in another TextInput. Un-nest your texts to make them selectable. If you need rich text formatting I unfortunately don't have an answer.

    @hoanvnbka selectable is a react native feature that's usually reliable on iOS. On Android, the Emulator tends to stop responding to the long press after a while, so you'll need to restart the emulator to fix it. If you still need help, you need to provide more information than 'did not work'. Try posting on Stack Overflow with the solution I gave, a detailed explanation of the problem and what you tried to fix it.

  25. acro5piano commented on Nov 26, 2019

    @acro5piano

    @scarlac
    Thank you for your answer!

  26. locked as resolved and limited conversation to collaborators on Dec 11, 2019
  27. unlocked this conversation on Jan 6, 2024
  28. fabOnReact commented on Jan 18, 2024

    @fabOnReact
    Contributor

    Hello,

    Thanks for the issue. I have been contributing to facebook/react-native for 4 years and specialize in the Text/TextInput components. I currently have 58 facebook/react-native PRs:

    https://github.com/facebook/react-native/pulls?q=is%3Apr+author%3Afabriziobertoglio1987+

    It is the suggested approach from the react-native core team (see this discussion).

    I'm publishing several fixes for Text and TextInput component in a separate library react-native-improved.

    • The Component is based on ReactTextView, it is the same implementation from react-native.
    • It will include several bug fixes.
    • You can use the library until the PR is merged and released with react-native.
    • You can use side by side both components from react-native and react-native-improved, depending on where you need the fix.
    • I will also publish the PR to facebook/react-native (daily fixes and releases).

    The advantages would be:

    • Increased engagement with the community, issues are quickly fixed.
    • No limitations when merging PRs (react-native main branch is used on facebook marketplace).
    • Only Meta employees can merge and review facebook/react-native PRs.
    • Allows us to further experiment and develop react-native.

    Do you want me to publish for you a patched release? I'm working on a list of priorities. Thanks

  29. johnlahut commented on Feb 20, 2024

    @johnlahut

    Use a <TextInput/> on iOS to allow multiple actions and use a regular <Text/> on Android. That will allow specific word selection on both platforms. No linking. No native libraries. Just use this:

    import { Platform } from 'react-native';
    // ...
    {Platform.OS === 'ios' ? (
      // iOS requires a textinput for word selections
      <TextInput
        value={description}
        editable={false}
        multiline
      />
    ) : (
      // Android can do word selections just with <Text>
      <Text selectable>{description}</Text>
    )}

    Result, Android: image

    Result, iOS: image

    @scarlac Are you aware of a way to make the <TextInput/> component selectable in iOS without having multiline set? In a few of my components I don't want text to wrap, but I'd still like the visible text to be selectable.

  30. scarlac commented on Feb 21, 2024

    @scarlac
    Contributor

    @johnlahut i'am not currently aware of a method but I haven't checked since that post so perhaps there are ways now that I'm not aware of. If you find one please share.

  31. AkbarBakhshi commented on Mar 12, 2024

    @AkbarBakhshi

    Use a <TextInput/> on iOS to allow multiple actions and use a regular <Text/> on Android. That will allow specific word selection on both platforms. No linking. No native libraries. Just use this:

    import { Platform } from 'react-native';
    // ...
    {Platform.OS === 'ios' ? (
      // iOS requires a textinput for word selections
      <TextInput
        value={description}
        editable={false}
        multiline
      />
    ) : (
      // Android can do word selections just with <Text>
      <Text selectable>{description}</Text>
    )}

    Result, Android: image

    Result, iOS: image

    This worked for me. Thanks 👍 . For me adding scrollEnabled={false} to the TextInput also helped with some undesired scrolling..

  32. haileyok commented on Mar 19, 2024

    @haileyok
    Contributor

    Dropping this here https://github.com/bluesky-social/react-native-uitextview

    This works (mostly, it's a WIP but also not much time to fully implement everything) on iOS for text selection. Uses RN Text on Android and web since no changes are needed there, and a native component on iOS that uses UITextView over UILabel. We are using this in production though right now with no issues.

    Contribs are more than welcome if you want to clean it up! Some styles are missing, etc. right now.

    @fabOnReact Totally feel free to take it and clean it up if you ever want to. From what I've seen you do a lot of good work with Text so you probably have a way better idea of how to implement this than I do ❤️ (same to anyone else)

  33. lsarni commented on Jul 11, 2024

    @lsarni

    In our case we need to have text formatting, and because the value of a TextInput can only be a string the workaround doesn't work. It would be great to have Text working on iOS the way it does on Android.

  34. bubblesunyum commented on Jul 29, 2024

    @bubblesunyum

    surprised & devastated that this is not a react native feature :(
    +1 to prioritize this since text is a fundamental piece of most apps and should be fully natively supported

  35. removed
    Resolution: For Stack OverflowA question for Stack Overflow. Applying this label will cause issue to be closed.
    on Oct 15, 2024
  36. princektripathi commented on Nov 14, 2024

    @princektripathi
    Collaborator

    Hello @cipolleschi , @cortinico,

    I debugged the partial text selection issue because it intrigued me, especially since it’s been open since 2017. Here are my findings:

    • RCTParagraphTextView extends UIView, which does not support partial text selection.
    • Partial text selection is only available in UIKit’s UITextView. Also, neither Text nor any View in SwiftUI supports partial selection.

    Possible Solution

    • To support partial text selection, we would need to use UIKit’s UITextView.
    • Alternatively, we could implement custom partial text selection logic within UIView.

    Cons

    • Using UITextView could limit the flexibility of custom drawing we initially intended by extending UIView.
    • Implementing custom partial selection logic adds unnecessary complexity, as it bypasses the native capabilities of UITextView

    I created a sample app showcasing all major combinations of selectable texts:

    • UIKit: UITextView, UIView (manual text selection handling).
    • SwiftUI: Text, UIViewRepresentable (manual text selection handling).

    Sample - https://github.com/PrinceK001/RNPlayground

    Could you please validate my understanding?

    API Ref -
    Screenshot 2024-11-14 at 7 06 00 PM

  37. princektripathi commented on Nov 15, 2024

    @princektripathi
    Collaborator

    @cortinico, @cipolleschi, there is another issue reported citing the exact same behaviour. Looking forward to hear your opinion and conclude this issue.

    #33494

  38. react-native-bot commented on May 15, 2025

    @react-native-bot
    Collaborator

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  39. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on May 15, 2025
  40. react-native-bot commented on May 22, 2025

    @react-native-bot
    Collaborator

    This issue was closed because it has been stalled for 7 days with no activity.

  41. lsarni commented on May 22, 2025

    @lsarni

    The issue isn't resolved

  42. removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Jun 10, 2025
  43. ashutoshup99 commented on Jul 22, 2025

    @ashutoshup99

    Is there any solution for this till now ?

  44. colaquecez commented on Oct 5, 2025

    @colaquecez

    I created that lib for android: https://github.com/colaquecez/expo-selectable-text, but I need to spend more time on it to make it better.

  45. react-native-bot commented on Apr 3, 2026

    @react-native-bot
    Collaborator

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  46. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Apr 3, 2026
  47. CanRau commented on Apr 4, 2026

    @CanRau

    Please don't close 🫪

  48. removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Apr 4, 2026
  49. elstgav commented on Apr 13, 2026

    @elstgav
  50. aretrace commented on Apr 20, 2026

    @aretrace

    What should we make of this? 9+ years. A fair point would be that if 'we' all want it so much, 'we' should code it up. But solutions have been made, yet no real progress has been done.
    Doesn't anyone find this strange? These long issues (e.g., the Gnome file picker thumbnail fiasco) are so universally wanted and objectively needed but remain frozen for decades.
    I think a new field of open source anthropology should start; I suspect there is more here than meets the eye.

  51. raajnadar commented on Sep 6, 2026

    @raajnadar

    I tried to solve #58363. Can someone look into it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions