question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Chip] How can I make the text selectable?

See original GitHub issue

I want to make the text inside a Chip selectable so that users may copy the content. despite my best efforts, when i click inside the component the text is not selectable.

import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';

import { withStyles } from '@material-ui/core/styles';
import FaceIcon from '@material-ui/icons/Face';
import Avatar from '@material-ui/core/Avatar';
import Chip from '@material-ui/core/Chip';
import Typography from '@material-ui/core/Typography';
import { emphasize, fade, darken } from '@material-ui/core/styles/colorManipulator';

import {stringToColor} from '../Generic/RandomColor';

const styles = theme => ({
  root: {
    whiteSpace: 'nowrap',
    cursor: 'inherit',
    userSelect: 'text',
  },
  label: {
    userSelect: 'text',
    whiteSpace: 'nowrap',
    cursor: 'inherit',
  },
  clickable: {
    cursor: 'text',
    userSelect: 'text',
  },
  separator: {
    marginRight: theme.spacing.unit,
  },
  fright: {
    float: 'right',
  },
  fleft: {
    float: 'left',
  },
});

function ProfileChip(props) {
  const { fullname, username, classes, theme } = props;
  return (
      <Link to={`/profile/${ username }`}>
        <span>
        <React.Fragment>
        <Chip
          component='object'
          clickable
          variant="outlined"
          classes={classes}
          label={ `${fullname} @${username}` }
          className={`${classes.chip} ${classes.fleft}`}
        />
        </React.Fragment>
        </span>
      </Link>
  );
}


ProfileChip.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles, {withTheme: true})(ProfileChip);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
paulintrognoncommented, Sep 2, 2021

I managed to make it work, text will be selectable again 🎉

<Chip sx={{ userSelect: 'unset' }} />
1reaction
eps1loncommented, Nov 14, 2018

Looking through the material design spec chips are always clickable and I agree with @mbrookes that clickable elements should not have text selection by default. I would however agree that if they are not clickable (as shown in the demos) then we should enable text selection.

Although I would not do it. Makes it less clear what a chip represents if it’s sometimes used as a simple stylistic wrapper for some special text.

[…] portions that are clickable, but one displays an id (to maintain visual consistency) […]

That’s what I mean. If they do different things then they shouldn’t be visually consistent. Could you show me reference implementation? Maybe I’m not getting something.

However mwc and material angular enable text selection while not using the pointer cursor. The latter does not match the spec though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Chip] How can I make the text selectable? #13564 - GitHub
I want to make the text inside a Chip selectable so that users may copy the content. despite my best efforts, when i...
Read more >
Android text view with chip type selectable boxes
Here you can see that the first item is a background for the state "checked". It contains the rectangle shape with rounded corners...
Read more >
How to make Text Selectable in Android using Jetpack ...
In this article, we will use Android's Jetpack Compose to create those chips. A sample image is given below to give an idea...
Read more >
SelectableText class - material library - Flutter - Dart API docs
A run of selectable text with a single style. The SelectableText widget displays a string of text with a single style. The string...
Read more >
cannot select text with microsoft word in M1 chip Macbook pro
Hi, My laptop is Macbook pro with m1 chip, Big Sur. I cannot select any text using in trackpad( I tried to select...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found