Rating
Ratings give users a way to quickly view and provide feedback.
<pc-rating label="Rating"></pc-rating>
Demos
Labels
Ratings are commonly identified contextually, so labels aren’t displayed. However, you should always provide one for assistive devices using the label
attribute.
Maximum value
The rating’s maximum value is 5 by default. To change the maximum value, use the max
attribute.
Precision
Use the precision
attribute to let users select fractional ratings.
Icon size
Set the --icon-size
custom property to adjust the size.
Read‐only
Use the readonly
attribute to display a rating that users can’t change.
Disabled
Use the disabled
attribute to disable the rating.
Detecting hover
Use the pc-hover
event ot detect when the user hovers over (or touches and drags) the rating. This lets you hook into values as the user interacts with the rating before they select a value.
This event has a payload with phase
and value
properties. The phase
property tells when hovering starts, moves to a new value and ends. The value
property tells what the rating’s value would be if the user were to commit to the hovered value.
Custom icons
You can provide custom icons by passing a function to the getIcon
property.
Value‐based icons
You can also use the getIcon
property to render different icons based on the value chosen on the rating.
Properties
Name | Description | Reflects | Default |
---|---|---|---|
dependencies | object | { "pc-icon": PcIcon } | |
rating | HTMLElement | - | |
disabled | boolean | false | |
label | string | "" | |
max | number | 5 | |
precision | number | 1 | |
readonly | boolean | false | |
value | number | 0 | |
getIcon | (value: number) => string | - | |
updateComplete | A read‐only promise that resolves when the component has finished updating. | - |
Learn more about attributes and properties.
Methods
Name | Description | Arguments |
---|---|---|
handleHoverValueChange() | - | |
handleIsHoveringChange() | - | |
focus() | options: FocusOptions | |
blur() | - |
Learn more about methods.
Importing
If you’re using the autoloader or the standard loader, you can ignore this section. If you’re cherry picking, you can use any of the following snippets to import this component.
To import this component from the CDN with a script tag, copy this snippet and paste it in your HTML.
<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@0.5.1/dist/components/rating/rating.js"></script>
To import this component from the CDN using a JavaScript import, copy this snippet and paste it in your JavaScript:
import "https://cdn.jsdelivr.net/npm/placer-toolkit@0.5.1/dist/components/rating/rating.js";
To import this component with a bundler using a JavaScript import, copy this snippet and paste it in your JavaScript:
import "placer-toolkit/dist/components/rating/rating.js";