29

I want users to be able to select text content (in ionic 2) so that they can copy it and paste it elsewhere, but it seems that text selection has been disabled. Users can select text that is in an input or a textarea, but I want them to be able to select even regular content text. Is there a way to re-enable text selection?

Manspof
  • 598
  • 26
  • 81
  • 173

5 Answers5

60

I added

body {
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
}

to the app.scss file

For individual items, since this is SCSS, you can also create a mix-in with those 4 css lines. Keep in mind Safari or other browsers may not respond well to just user-select.

Dmitri R117
  • 2,502
  • 23
  • 20
16

You need to add the following CSS to the HTML tag you want to be selectable

user-select: text;
Alexander Ciesielski
  • 10,506
  • 5
  • 45
  • 66
3

For my Ionic 4 project, using the body tag didn't work but this did:

* {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}
Matthew
  • 2,871
  • 5
  • 34
  • 59
2

In Ionic 4 add

* {

    -webkit-user-select: text;
    
    -moz-user-select: text;
    
    -ms-user-select: text;
    
    user-select: text;
    
    }

**to the global.scss file. ** But if you want to copy/paste only a specific tag text, add something like this instead in your global.scss:

.selectable {

    -webkit-user-select: text;
    
    -moz-user-select: text;
    
    -ms-user-select: text;
    
    user-select: text;
    
    }

And then add class="selectable" property to the tag.

Hope it helps

lionmo
  • 21
  • 2
2

You do not have to use the wildcard selector to apply the fix like others have stated. If you use remote debugging in the browser, you can select any element and find what is setting its styles.

  • Open dev tools
  • Select the element you want to inspect with Ctrl + Shift + C
  • Go to the computed tab
  • Find the style, in this case, user-select
  • Click on the none option underneath

Computed dev tools tab

enter image description here

  • It should take you to where it's being set. html.plt-mobile ion-app is the CSS selector being applied. Now all you have to do is target that selector in your own stylesheet.

    html.plt-mobile ion-app {
         -webkit-user-select: auto;
         -moz-user-select: auto;
         -ms-user-select: auto;
         user-select: auto;
    }
    
Dan
  • 53
  • 1
  • 6