1e41f4b71Sopenharmony_ci# rating 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **NOTE** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThe **\<rating>** component provides a rating bar used for reviews and ratings. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Required Permissions 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciNone 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Child Components 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciNot supported 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## Attributes 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 25e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 26e41f4b71Sopenharmony_ci| numstars | number | 5 | No| Maximum number of rating stars.| 27e41f4b71Sopenharmony_ci| rating | number | 0 | No| Number of stars rated.| 28e41f4b71Sopenharmony_ci| stepsize | number | 0.5 | No| Step to increase the rating value.| 29e41f4b71Sopenharmony_ci| indicator | boolean | false | No| Whether to make the rating icons as an indicator (not-editable by users).| 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci## Styles 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciIn addition to the [universal styles](js-components-common-styles.md), the following styles are supported. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 37e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 38e41f4b71Sopenharmony_ci| star-background | string | - | No| Background image when a rating star is unselected. Only PNG and JPG images in a local path are supported.| 39e41f4b71Sopenharmony_ci| star-foreground | string | - | No| Foreground image when a rating star is selected. Only PNG and JPG images in a local path are supported.| 40e41f4b71Sopenharmony_ci| star-secondary | string | - | No| Secondary background image when a rating star is partially selected. This image will cover the background image and can only be a PNG or JPG image from a local path.| 41e41f4b71Sopenharmony_ci| width | <length>\|<percentage> | 120px<br>60 px (cannot be edited)| No| Image width. The default value is the width of the default image for five-star ratings. If you do not set the maximum rating value and background images of the rating stars, the default value will be used.| 42e41f4b71Sopenharmony_ci| height | <length>\|<percentage> | 24px<br>12px (cannot be edited)| No| Image height. The default value is the height of the default image for five-star ratings. If you do not set the maximum rating value and background images of the rating stars, the default value will be used.| 43e41f4b71Sopenharmony_ci| rtl-flip | boolean | true | No| Whether the image source is automatically flipped in the RTL text direction.| 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci> **NOTE** 46e41f4b71Sopenharmony_ci> 47e41f4b71Sopenharmony_ci> You must set **star-background**, **star-secondary**, and **star-foreground**. Otherwise, the rating star is gray, indicating that the image is set incorrectly. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci## Events 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciIn addition to the [universal events](js-components-common-events.md), the following events are supported. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci| Name| Parameter| Description| 55e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 56e41f4b71Sopenharmony_ci| change | { rating: number } | Triggered when the rating value changes.| 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci## Methods 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ciThe [universal methods](js-components-common-methods.md) are supported. 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci## Example 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci```html 67e41f4b71Sopenharmony_ci<!-- xxx.hml --> 68e41f4b71Sopenharmony_ci<div class="container"> 69e41f4b71Sopenharmony_ci <rating numstars="5" rating="5" @change="changeRating" id="rating"> 70e41f4b71Sopenharmony_ci </rating> 71e41f4b71Sopenharmony_ci</div> 72e41f4b71Sopenharmony_ci``` 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci```css 75e41f4b71Sopenharmony_ci/* xxx.css */ 76e41f4b71Sopenharmony_ci.container { 77e41f4b71Sopenharmony_ci display: flex; 78e41f4b71Sopenharmony_ci justify-content: center; 79e41f4b71Sopenharmony_ci align-items: center; 80e41f4b71Sopenharmony_ci} 81e41f4b71Sopenharmony_cirating { 82e41f4b71Sopenharmony_ci width: 200px; 83e41f4b71Sopenharmony_ci} 84e41f4b71Sopenharmony_ci``` 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci```js 87e41f4b71Sopenharmony_ci// xxx.js 88e41f4b71Sopenharmony_ciimport promptAction from '@ohos.promptAction'; 89e41f4b71Sopenharmony_ciexport default { 90e41f4b71Sopenharmony_ci changeRating(e){ 91e41f4b71Sopenharmony_ci promptAction.showToast({ 92e41f4b71Sopenharmony_ci message: e.rating 93e41f4b71Sopenharmony_ci }); 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci} 96e41f4b71Sopenharmony_ci``` 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci 99