3
votes

This is mainly to define browser specific values like this one for a given CSS property:

<div style="cursor: -moz-grab; cursor: -webkit-grab; cursor: grab;">Grab me!</div>

If I wrap it into object like this:

<div style={{
    cursor: "-moz-grab",
    cursor: "-webkit-grab",
    cursor: "grab"
}}>Grab me!</div>

then you duplicate keys in an object (would fail in strict mode and would overwrite otherwise). And simply putting all values into single string doesn't seem to work either.

Figuring out browser with JS and then applying right value seems to be too much work.. Or is there a different approach to do this? Any ideas?

2
I guess you need it as a string... var style = 'cursor: "-moz-grab", cursor: "-webkit-grab", cursor: "grab" '; return <div style={style}>Grab me!</div> Maybe not the best way but I can't think of anything else. You should also take a look to autoprefixer github.com/postcss/autoprefixeralexmngn
@alexmngn: in react, you can't pass style as string.. it's only object, isn't it?Sherzod

2 Answers

2
votes

If you want to use inline styles and also get vendor prefixing, you can use a library like Radium to abstract the vendor prefixing for you.

By adding a @Radium decorator to your component, Radium will hook into the styles you pass to the component and automatically manage and prefix them.

var Radium = require('radium');
var React = require('react');

@Radium
class Grabby extends React.Component {
  render() {
    return (
      <div style={style}>
        {this.props.children}
      </div>
    );
  }
}

var style = {
  cursor: "grab" // this will get autoprefixed for you!
};
0
votes

The best you could do is to create a css class with the cursor attribute, and add it to your component

.container {
  height: 10px;
  width: 10px;
}

.grab {
  cursor: -moz-grab,
  cursor: -webkit-grab,
  cursor: grab,
}

Then in your react component:

var isGrabEnabled = true;

<div className={['container', (isGrabEnabled ? 'grab' : '')]}>Grab me!</div>