Rating
Rating widgets are Input Fields that score something in stars, such as a review. Their value is the number of stars picked, a whole number from 1 to the number of stars, which is 5 by default.
import { gui } from '@golemui/gui-shared';
export default [ gui.inputs.rating('service', { label: 'Service', }),];{ "$schema": "https://golemui.com/schemas/form.schema.json", "form": [ { "kind": "input", "type": "rating", "path": "service", "label": "Service" } ]}The stars are native radio buttons: the arrow keys move between them and pick one, and screen readers read “1 star” to “5 stars”. The pointer previews a rating as it moves over the stars.
Until the user picks a star, or the form sets a defaultValue, the rating has no value. A click on the picked star clears it, and so do Delete and Backspace. For a score on a longer or finer scale, use a Slider.
Use these props to customize your Rating widget.
| prop | type | description |
|---|---|---|
hint | string | Description text displayed below the label |
Use the property hint to provide instructions for the user.
import { gui } from '@golemui/gui-shared';
export default [ gui.inputs.rating('food', { hint: 'Click the picked star again, or press Delete, to clear it.', label: 'Food', }),];{ "$schema": "https://golemui.com/schemas/form.schema.json", "form": [ { "kind": "input", "type": "rating", "path": "food", "label": "Food", "props": { "hint": "Click the picked star again, or press Delete, to clear it." } } ]}Number of stars
Section titled “Number of stars”A rating has no max prop: the maximum of its integer validator is the number of stars. A defaultValue picks a rating from the start.
import { gui } from '@golemui/gui-shared';
export default [ gui.inputs.rating('stay', { label: 'Your stay', validator: { maximum: 10, }, defaultValue: 7, }),];{ "$schema": "https://golemui.com/schemas/form.schema.json", "form": [ { "kind": "input", "type": "rating", "path": "stay", "label": "Your stay", "defaultValue": 7, "validator": { "type": "integer", "maximum": 10 } } ]}Validation
Section titled “Validation”A Rating takes an integer validator. With required, the user can still clear the rating: a cleared required rating shows its error, as an emptied text field does.
A rating with no value fails the integer type check before required, so word the missing value with messages.invalid.
import { gui } from '@golemui/gui-shared';
export default [ gui.inputs.rating('overall', { label: 'Overall', validator: { required: true, messages: { invalid: 'Rate your experience', }, }, }),];{ "$schema": "https://golemui.com/schemas/form.schema.json", "form": [ { "kind": "input", "type": "rating", "path": "overall", "label": "Overall", "validator": { "type": "integer", "required": true, "messages": { "invalid": "Rate your experience" } } } ]}Styling
Section titled “Styling”Ratings can be styled as explained in the Styling Guide.
CSS Variables
Section titled “CSS Variables”Following you will find a list with the CSS Variables and a quick description of what you will style.
| CSS Variable | Description |
|---|---|
--gui-rating-size | Width and height of each star. Defaults to 1.5rem |
--gui-rating-gap | Space between two stars. Defaults to 0.125rem |
--gui-rating-fill | Fill and outline of a picked star. A warning tone that reaches 3:1 contrast |
--gui-border-strong | Outline of an empty star |
--gui-border-focus | Focus ring around the focused star |
--gui-intent-error | Outline of the empty stars while the rating shows an error |
Anatomy
Section titled “Anatomy”This is the anatomy of the Rating Widget in case you want to use your CSS styles.
<gui-rating-input class="gui-rating gui-field"> <gui-rating class="gui-field"> <span class="gui-label" id="fieldUid_label"> <span class="gui-label__text">Label</span> <div class="gui-widget-hint" id="fieldUid_hint" aria-hidden="true">Hint</div> </span>
<div class="gui-widget"> <div role="radiogroup" class="gui-rating__stars" id="fieldUid" aria-labelledby="fieldUid_label" aria-describedby="fieldUid_hint" > <label class="gui-rating__star gui-rating__star--filled" for="fieldUid_1"> <input type="radio" class="gui-rating__input gui-visually-hidden" id="fieldUid_1" name="fieldUid" form="fieldUid_none" value="1" tabindex="-1" aria-label="1 star" aria-describedby="fieldUid_hint" /> <svg viewBox="0 0 24 24" class="gui-rating__glyph" aria-hidden="true"> <polygon points="12,2 14.49,9.17 …"></polygon> </svg> </label> <label class="gui-rating__star gui-rating__star--filled" for="fieldUid_2"> <input type="radio" class="gui-rating__input gui-visually-hidden" id="fieldUid_2" name="fieldUid" form="fieldUid_none" value="2" tabindex="0" aria-label="2 stars" aria-describedby="fieldUid_hint" /> <svg viewBox="0 0 24 24" class="gui-rating__glyph" aria-hidden="true"> <polygon points="12,2 14.49,9.17 …"></polygon> </svg> </label> <!-- More stars, up to the validator's maximum (5 by default) --> </div> </div>
<div class="gui-validator gui-validator--empty" id="fieldUid_errors" role="alert"></div> </gui-rating></gui-rating-input>