logoAnt Design

⌘ K
  • 设计
  • 研发
  • 组件
  • 博客
  • 资源
5.3.3
  • 组件总览
  • 通用
    • Button按钮
    • Icon图标
    • Typography排版
  • 布局
    • Divider分割线
    • Grid栅格
    • Layout布局
    • Space间距
  • 导航
    • Anchor锚点
    • Breadcrumb面包屑
    • Dropdown下拉菜单
    • Menu导航菜单
    • Pagination分页
    • Steps步骤条
  • 数据录入
    • AutoComplete自动完成
    • Cascader级联选择
    • Checkbox多选框
    • DatePicker日期选择框
    • Form表单
    • Input输入框
    • InputNumber数字输入框
    • Mentions提及
    • Radio单选框
    • Rate评分
    • Select选择器
    • Slider滑动输入条
    • Switch开关
    • TimePicker时间选择框
    • Transfer穿梭框
    • TreeSelect树选择
    • Upload上传
  • 数据展示
    • Avatar头像
    • Badge徽标数
    • Calendar日历
    • Card卡片
    • Carousel走马灯
    • Collapse折叠面板
    • Descriptions描述列表
    • Empty空状态
    • Image图片
    • List列表
    • Popover气泡卡片
    • QRCode二维码
    • Segmented分段控制器
    • Statistic统计数值
    • Table表格
    • Tabs标签页
    • Tag标签
    • Timeline时间轴
    • Tooltip文字提示
    • Tour漫游式引导
    • Tree树形控件
  • 反馈
    • Alert警告提示
    • Drawer抽屉
    • Message全局提示
    • Modal对话框
    • Notification通知提醒框
    • Popconfirm气泡确认框
    • Progress进度条
    • Result结果
    • Skeleton骨架屏
    • Spin加载中
  • 其他
    • Affix固钉
    • App包裹组件
    • ConfigProvider全局化配置
    • FloatButton悬浮按钮
    • Watermark水印
何时使用
代码演示
基本
半星
文案展现
只读
清除
其他字符
自定义字符
API
方法

Rate评分

Radio单选框Select选择器

相关资源

Ant Design Charts
Ant Design Pro
Ant Design Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Landing-首页模板集
Scaffolds-脚手架市场
Umi-React 应用开发框架
dumi-组件/文档研发工具
qiankun-微前端框架
ahooks-React Hooks 库
Ant Motion-设计动效
国内镜像站点 🇨🇳

社区

Awesome Ant Design
Medium
Twitter
yuqueAnt Design 语雀专栏
Ant Design 知乎专栏
体验科技专栏
seeconfSEE Conf-蚂蚁体验科技大会
加入我们

帮助

GitHub
更新日志
常见问题
报告 Bug
议题
讨论区
StackOverflow
SegmentFault

Ant XTech更多产品

yuque语雀-构建你的数字花园
AntVAntV-数据可视化解决方案
EggEgg-企业级 Node.js 框架
kitchenKitchen-Sketch 工具集
xtech蚂蚁体验科技
主题编辑器
Made with ❤ by
蚂蚁集团和 Ant Design 开源社区

评分组件。

何时使用

  • 对评价进行展示。
  • 对事物进行快速的评级操作。

代码演示

基本

最简单的用法。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'antd';

const App: React.FC = () => <Rate />;

export default App;
normal
文案展现

给评分组件加上文案展示。

expand codeexpand code
TypeScript
JavaScript
import React, { useState } from 'react';
import { Rate } from 'antd';

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

const App: React.FC = () => {
  const [value, setValue] = useState(3);

  return (
    <span>
      <Rate tooltips={desc} onChange={setValue} value={value} />
      {value ? <span className="ant-rate-text">{desc[value - 1]}</span> : ''}
    </span>
  );
};

export default App;
allowClear: true
allowClear: false
清除

支持允许或者禁用清除。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'antd';

const App: React.FC = () => (
  <>
    <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>
  </>
);

export default App;
  • 1
    1
  • 2
    2
  • 3
    3
  • 4
    4
  • 5
    5

自定义字符

可以使用 (RateProps) => ReactNode 的方式自定义每一个字符。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { FrownOutlined, MehOutlined, SmileOutlined } from '@ant-design/icons';
import { Rate } from 'antd';

const customIcons: Record<number, React.ReactNode> = {
  1: <FrownOutlined />,
  2: <FrownOutlined />,
  3: <MehOutlined />,
  4: <SmileOutlined />,
  5: <SmileOutlined />,
};

const App: React.FC = () => (
  <>
    <Rate defaultValue={2} character={({ index }: { index: number }) => index + 1} />
    <br />
    <Rate defaultValue={3} character={({ index }: { index: number }) => customIcons[index + 1]} />
  </>
);

export default App;
半星

支持选中半星。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'antd';

const App: React.FC = () => <Rate allowHalf defaultValue={2.5} />;

export default App;
只读

只读,无法进行鼠标交互。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'antd';

const App: React.FC = () => <Rate disabled defaultValue={2} />;

export default App;

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

  • 好
    好
  • 好
    好
  • 好
    好
  • 好
    好
  • 好
    好
其他字符

可以将星星替换为其他字符,比如字母,数字,字体图标甚至中文。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { HeartOutlined } from '@ant-design/icons';
import { Rate } from 'antd';

const App: React.FC = () => (
  <>
    <Rate character={<HeartOutlined />} allowHalf />
    <br />
    <Rate character="A" allowHalf style={{ fontSize: 36 }} />
    <br />
    <Rate character="好" allowHalf />
  </>
);

export default App;

API

属性说明类型默认值版本
allowClear是否允许再次点击后清除booleantrue
allowHalf是否允许半选booleanfalse
autoFocus自动获取焦点booleanfalse
character自定义字符ReactNode | (RateProps) => ReactNode<StarFilled />function(): 4.4.0
className自定义样式类名string-
countstar 总数number5
defaultValue默认值number0
disabled只读,无法进行交互booleanfalse
style自定义样式对象CSSProperties-
tooltips自定义每项的提示信息string[]-
value当前数,受控值number-
onBlur失去焦点时的回调function()-
onChange选择时的回调function(value: number)-
onFocus获取焦点时的回调function()-
onHoverChange鼠标经过时数值变化的回调function(value: number)-
onKeyDown按键回调function(event)-

方法

名称描述
blur()移除焦点
focus()获取焦点