[Chip] How can I make the text selectable?
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:3
- Comments:18 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I managed to make it work, text will be selectable again 🎉
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.
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.