Rate

Rate component.

When To Use#

  • Show evaluation.

  • A quick rating operation on something.

Examples

The simplest usage.

expand codeexpand code
import { Rate } from 'antd';

ReactDOM.render(<Rate />, mountNode);
3 stars

Add copywriting in rate components.

expand codeexpand code
import { Rate } from 'antd';

class Rater extends React.Component {
  state = {
    value: 3,
  }

  handleChange = (value) => {
    this.setState({ value });
  }

  render() {
    const { value } = this.state;
    return (
      <span>
        <Rate onChange={this.handleChange} value={value} />
        {value && <span className="ant-rate-text">{value} stars</span>}
      </span>
    );
  }
}

ReactDOM.render(<Rater />, mountNode);
allowClear: true
allowClear: false

Support set allow to clear star when click again.

expand codeexpand code
import { Rate } from 'antd';

ReactDOM.render(
  <div>
    <Rate defaultValue={3} /> allowClear: true
    <br />
    <Rate allowClear={false} defaultValue={3} /> allowClear: false
  </div>,
  mountNode);

Support select half star.

expand codeexpand code
import { Rate } from 'antd';

ReactDOM.render(<Rate allowHalf defaultValue={2.5} />, mountNode);

Read only, can't use mouse to interact.

expand codeexpand code
import { Rate } from 'antd';

ReactDOM.render(<Rate disabled defaultValue={2} />, mountNode);


Replace the default star to other character like alphabet, digit, iconfont or even Chinese word.

expand codeexpand code
import { Rate, Icon } from 'antd';

ReactDOM.render(
  <div>
    <Rate character={<Icon type="heart" />} allowHalf />
    <br />
    <Rate character="A" allowHalf style={{ fontSize: 36 }} />
    <br />
    <Rate character="" allowHalf />
  </div>,
  mountNode);

API#

PropertyDescriptiontypeDefault
allowClearwhether to allow clear when click againbooleantrue
allowHalfwhether to allow semi selectionbooleanfalse
autoFocusget focus when component mountedbooleanfalse
charactercustom character of rateReactNode<Icon type="star" />
classNamecustom class name of ratestring-
countstar countnumber5
defaultValuedefault valuenumber0
disabledread only, unable to interactbooleanfalse
stylecustom style object of rateobject-
valuecurrent valuenumber-
onBlurcallback when component lose focusFunction()-
onChangecallback when select valueFunction(value: number)-
onFocuscallback when component get focusFunction()-
onHoverChangecallback when hover itemFunction(value: number)-
onKeyDowncallback when keydown on componentFunction(event)-

Methods#

NameDescription
blur()remove focus
focus()get focus