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);
normal

Add copywriting in rate components.

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

const desc = ['terrible', 'bad', 'normal', 'good', 'wonderful'];

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

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

  render() {
    const { value } = this.state;
    return (
      <span>
        <Rate tooltips={desc} onChange={this.handleChange} value={value} />
        {value ? <span className="ant-rate-text">{desc[value - 1]}</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} />
    <span className="ant-rate-text">allowClear: true</span>
    <br />
    <Rate allowClear={false} defaultValue={3} />
    <span className="ant-rate-text">allowClear: false</span>
  </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);

  • A
    A
  • A
    A
  • A
    A
  • A
    A
  • A
    A

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#

PropertyDescriptiontypeDefaultVersion
allowClearwhether to allow clear when click againbooleantrue3.1.0
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-
tooltipsCustomize tooltip by each characterstring[]-3.12.0
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#

NameDescriptionVersion
blur()remove focus
focus()get focus
MentionsRadio