Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name of key in React.js for unselectable css

I defined a css object inside of my render method but I am trying to figure out how to make text unselectable. React.js has their own key names like backgroundColor instead of background-color for css objects. I am trying to figure out key name for unselectable styles? Example:

	render:function(){
		var ListItems={
			cursor:'pointer',
			color:'black',
			marginLeft:'-20px',
			marginTop:'-10px',
			marginBottom:'14px',
			userSelect:'none',
		}
		if(this.state.linkHover=='hoverLink'){
			ListItems.color='blue';
		}else{
			ListItems.color='black';
		}
			return (
				<div>
				<li style={ListItems} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} onClick={this.onClick}><input type="checkbox" checked={this.state.checked} unselectable="on"/>{this.props.value}</li>
				</div>
			)
	}

userSelect doesn't seem to work in Chrome. Is there a different name?

like image 804
Tim Avatar asked Aug 13 '15 21:08

Tim


People also ask

How do you make text unselectable in React?

You can use user-select: none; on the elements you don't want to be selectable by the user.

What is key in react JS?

A key is a unique identifier. In React, it is used to identify which items have changed, updated, or deleted from the Lists. It is useful when we dynamically created components or when the users alter the lists.

Is Key a keyword in React?

Yes, that is true, key is a restricted keyword and doesn't get propagated as props. Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name: const content = posts.

What is key and ID in React?

Key is kind of the id for the element, and it helps React to identify which element was changed, added, or removed. It's a good practice to select a value that is a unique identifier for an item in the array, commonly it's the ID. Let's modify our example.


1 Answers

user-select has the following css names:

-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;

According to this, react's names are:

MozUserSelect: "none"
WebkitUserSelect: "none"
msUserSelect: "none"

Every hyphen - and the following character is replaced by according uppercase letter.

like image 135
baao Avatar answered Sep 20 '22 20:09

baao