Rate
Rate component.
When To Use#
Show evaluation.
A quick rating operation on something.
Examples
import { Rate } from 'antd';
ReactDOM.render(<Rate />, mountNode);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);import { Rate } from 'antd';
ReactDOM.render(
  <>
    <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>
  </>,
  mountNode,
);- 11
 - 22
 - 33
 - 44
 - 55
 
import { Rate } from 'antd';
import { FrownOutlined, MehOutlined, SmileOutlined } from '@ant-design/icons';
const customIcons = {
  1: <FrownOutlined />,
  2: <FrownOutlined />,
  3: <MehOutlined />,
  4: <SmileOutlined />,
  5: <SmileOutlined />,
};
ReactDOM.render(
  <>
    <Rate defaultValue={2} character={({ index }) => index + 1} />
    <br />
    <Rate defaultValue={3} character={({ index }) => customIcons[index + 1]} />
  </>,
  mountNode,
);import { Rate } from 'antd';
ReactDOM.render(<Rate allowHalf defaultValue={2.5} />, mountNode);import { Rate } from 'antd';
ReactDOM.render(<Rate disabled defaultValue={2} />, mountNode);- AA
 - AA
 - AA
 - AA
 - AA
 
- 好好
 - 好好
 - 好好
 - 好好
 - 好好
 
import { Rate } from 'antd';
import { HeartOutlined } from '@ant-design/icons';
ReactDOM.render(
  <>
    <Rate character={<HeartOutlined />} allowHalf />
    <br />
    <Rate character="A" allowHalf style={{ fontSize: 36 }} />
    <br />
    <Rate character="好" allowHalf />
  </>,
  mountNode,
);API#
| Property | Description | type | Default | Version | 
|---|---|---|---|---|
| allowClear | Whether to allow clear when click again | boolean | true | |
| allowHalf | Whether to allow semi selection | boolean | false | |
| autoFocus | If get focus when component mounted | boolean | false | |
| character | The custom character of rate | ReactNode | (RateProps) => ReactNode | <StarFilled /> | function(): 4.4.0 | 
| className | The custom class name of rate | string | - | |
| count | Star count | number | 5 | |
| defaultValue | The default value | number | 0 | |
| disabled | If read only, unable to interact | boolean | false | |
| style | The custom style object of rate | CSSProperties | - | |
| tooltips | Customize tooltip by each character | string[] | - | |
| value | The current value | number | - | |
| onBlur | Callback when component lose focus | function() | - | |
| onChange | Callback when select value | function(value: number) | - | |
| onFocus | Callback when component get focus | function() | - | |
| onHoverChange | Callback when hover item | function(value: number) | - | |
| onKeyDown | Callback when keydown on component | function(event) | - | 
Methods#
| Name | Description | 
|---|---|
| blur() | Remove focus | 
| focus() | Get focus |