Rating
WdRating
Applicable Scenarios
For rating input and display, using intuitive icons to represent the rating value.
Basic Capabilities Description
- The basic properties support selecting the component size and setting the current rating value.
- The advanced properties of the Rating component support configuring min value, max value, numerical adjustment step size, icon color (effective when using built-in icons), custom icons, and a tooltip copy generation function.
Extended Scenarios Description
How to Configure Step Size and Icon Display Style
Example
Configure the step size to 0.5, adjust the icon color, and set up custom icons.
Configuration Method
Configure Step Size: In the Scoring Attributes Area - Score Selector - Numerical Adjustment Step Size, enter 0.5
as the target step size.
Adjust icon color: In the Scoring Attributes Area - Score Selector - Icon Selected Color, enter rgb(255, 119, 158)
as the target color; in the Icon Unselected Color input field below, enter rgb(132, 106, 165)
as the target color.
Configure custom icons: In the Scoring Attributes Area - Score Selector - Default Icon, you can select the icon representing the current rating value; in the Scoring Attributes Area - Score Selector - Background Icon, you can select the icon to be displayed in the background. Both support selecting built-in icons and custom icons.
Example
Interactive Preview
Configure Minimum Value, Maximum Value, and Step Size
Custom Icon Color
Custom Icons
Configure Different Sizes
Custom Prompt Text
{
tooltip: ({ value }) => `Current rating value is: ${value}`;
}
Properties
External properties received by the component
Property Name | Property Identifier | Type | Description |
---|
显示标题 | labelVisible | boolean | Default value: true |
标题对齐 | labelAlign | string | 表单场景下默认会跟随表单容器的标题对齐配置 |
标题换行 | labelWrap | boolean | 如果标题内容过长关闭时只显示一行、溢出省略;开启时换行展示。表单场景下默认会跟随表单容器的标题换行配置 |
标题位置 | layout | string | 设置标题在表单组件的展示位置,表单场景下默认会跟随表单容器的标题的位置配置 |
标题宽度 | labelWidth | string | 表单场景下默认会跟随表单容器的标题宽度配置 |
标题提示 | labelTips | string | 配置标题的工具提示内容 |
最小值 | min | number | 0 |
最大值 | max | number | Default value: 5 |
数值调整步长 | step | number | 控制单次评分变化的最小幅度 Default value: 1 |
默认图标 | icon | string | 默认评分图标 Default value: "td:star-filled" |
自定义图标 | iconSrc | string | 设置自定义图标地址 |
未选中图标 | backgroundIcon | string | 评分背景图标 |
自定义未选中图标 | backgroundIconSrc | string | 设置自定义图标地址 |
图标选中颜色 | foregroundColor | string | Default value: "#ffcf48" |
图标未选中颜色 | backgroundColor | string | Default value: "#bfbfbf" |
移动端显示下划线 | borderedH5 | boolean | 关闭后移动端不显示底部下划线 Default value: true |
callbacks | object | 配置相关的函数 | |
状态 | status | string | Default value: "edit" |
必填 | required | boolean | 启用后该组件强制必填,值不可为空 |
必填标识 | requiredFlag | boolean | 启用后,组件若要求必填,则会显示必填星号标记 Default value: true |
必填校验提示 | requiredMsg | string | 启用必填,但组件值为空时的提示信息 Default value: "该项为必填项" |
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。页面内需保证唯一。 |
标题内容 | label | string | Example: "标题" |
评分值 | value | number | 当前评分值 |
组件尺寸 | size | string | 控制评分组件的大小 Default value: "sm" |
Events
Events exposed by the component. You can listen to component events to trigger external actions
Event Name | Event Code | Event Output Parameters event.detail | Applicable Scenarios | Description |
---|
值改变 | change | object
| Compatible with all platforms | - |
Property API
Through the Property API, you can access the internal state and property values of components. You can access internal values using$w.componentId.propertyName
, such as $w.input1.value
. For details, please refer to Property API
Read-only Property Name | Property Identifier | Type | Description |
---|
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。页面内需保证唯一。 |
标题内容 | label | string | |
评分值 | value | number | 当前评分值 |
最小值 | min | number | |
最大值 | max | number | |
数值调整步长 | step | number | 控制单次评分变化的最小幅度 |
是否展示 | visible | boolean | 组件是否展示 |
是否禁用 | disabled | boolean | 组件是否禁用 |
是否只读 | readOnly | boolean | 组件是否只读 |
Method API
Through the Method API, you can programmatically trigger internal methods of components, such as submitting forms, displaying popups, etc. You can call component methods using $w.componentId.methodName
, such as $w.form1.submit()
Method Name | Method Identifier | Parameters | Method Description |
---|
设置值 | setValue | number 值 | 通过 $w.id1.setValue("weda") 设置组件值 |
设置显隐 | setVisible | boolean 显示 | 通过 $w.id1.setVisible(false) 设置组件为隐藏 |
设置禁用 | setDisabled | boolean 禁用 | 通过 $w.id1.setDisabled(true) 设置组件为禁用 |
清空值 | clearValue | 通过 $w.id1.clearValue() 清空组件值 | |
设置只读 | setReadOnly | boolean 只读 | 通过 $w.id1.setReadOnly(true) 设置组件为只读 |
触发校验 | handleValidate | 通过 $w.id1.handleValidate() 校验组件值 | |
清除校验 | clearValidate | 通过 $w.id1.clearValidate() 清除组件校验 |
Style API
Through the Style API, you can override the styles of internal elements in components to achieve customization. For example, in the low-code editor, you can write styles for all button components using #wd-page-root .wd-btn
, and control individual component styles with :scope
. For detailed instructions, please refer toStyle API
Name | Class Name | Description and Examples |
---|
根元素 | .wd-rating-root | 组件最外层元素
|
H5 端根元素 | .wd-h5-rating-root | 可设定 H5 端的根元素样式
|
PC 端根元素 | .wd-pc-rating-root | 可设定 PC 端的根元素样式
|
小程序端根元素 | .wd-mp-rating-root | 可设定小程序端的根元素样式
|
组件标题样式 | .wd-rating-root .wd-form-item-wrap__label | 组件标题元素
|
编辑态-校验信息 | .wd-rating-root .wd-g-text-error | 设置组件校验信息样式
|
提示文字 | .wd-rating-root .wd-form-item__help-text | 设置组件提示文字样式
|
评分组件 | .wd-rating |
|
禁用态评分组件 | .wd-rating.is-disabled |
|
禁用态评分组件 | .wd-rating.is-readonly |
|
填充图标容器 | .wd-rating__full-icons-container | 填充图标元素们的父容器元素
|
背景图标容器 | .wd-rating__empty-icons-container | 背景图标元素们的父容器元素
|
图标容器 | .wd-rating__icon-container | 图标元素的父容器元素
|
图标 | .wd-rating__icon | 图标元素
|