deliteful/StarRating

The StarRating widget displays a rating, usually with stars, that can be edited by touching or clicking the stars.

StarRating Example

The StarRating widget is a form field, which means that when included in an HTML form, its value will be submitted with those of the other form fields, under the name defined by its nameattribute.

Table of Contents

Element Instantiation
Element Configuration
Element Styling
User Interactions
Mixins
Element Events
Enterprise Use

Element Instantiation

See delite/Widget for full details on how instantiation lifecycle is working.

Declarative Instantiation

<!-- Editable StarRating with: -->
<!-- * a minimum value of 0 -->
<!-- * a maximum value of 7 -->
<!-- * an initial value of 3.5 -->
<!-- * values set by increments of .5 -->
<d-star-rating name="rating" max="7" value="3.5" editHalfValues="true"></d-star-rating>

Programmatic Instantiation

require(["deliteful/StarRating", "requirejs-domready/domReady!"], function (StarRating) {
  var starRating = new StarRating({max: 7, value: 3.5, editHalfValues: true});
  starRating.placeAt(document.body);
});

Element Configuration

Using StarRating in a Form

The StarRating widget is a form field, which means that when included in an HTML form, its value will be submitted with those of the other form fields, under the name defined by its nameattribute.

Here is an example of a StarRating widget included in a form, under the name rating:

<form action="...">
    <span id="lb1">Rating:</span><d-star-rating id="input1" name="rating" value="4" aria-labelledby="lb1"></d-star-rating>
    <input type="submit">
</form>

Note that is the StarRating is disabled, its value will not be submited.

Properties

The following properties can be set on a StarRating instance:

Element Styling

Supported themes

This widget provides default styling for the following delite themes:

CSS Classes

The star characters displayed for an empty star and a full star are font characters. Half stars are created by displaying the first half of a full star character followed by the second half of an empty star character.

The stars displayed can be fully customized by using the following CSS selectors:

.d-star-rating-star-icon {
    font-size: 150%;
}

.d-star-rating-empty::before {
    content: "\2605"; /* The font character to use to display an empty star */
    color: #CCC; /* The color of an empty star */
}

.d-star-rating-full::before {
    content: "\2605"; /* The font character to use to display a full star */
    color: yellow; /* The color of a full star */
}

It is also possible to use an image stripes to render the stars, using a few more CSS selectors, as demonstrated in the following sample:

User Interactions

If the StarRating widget properties readOnly and / or disabled are not set to true, the value of the widget can be edited by:

Mixins

No mixin currently available for this widget.

Element Events

This widget emits a change event when its value is updated following a user action on the widget node. No change event is emitted if the value is updated programmatically.

Enterprise Use

Accessibility

The StarRating widget has an ARIA role of slider.

It is keyboard navigable: unless it is read only, its value can be edited using the arrow keys (see User Interactions).

Limitation when using Apple VoiceOver

When a deliteful/StarRating widget is selected in Safari while VoiceOver is on:

Globalization

deliteful/StarRating provide an internationalizable bundle that contains only one message, with the key aria-valuetext. This message supports the keyword ${value}, that is replaced by the current value of the widget to set its aria-valuetext property every time that the value is updated.

Right to left orientation is supported.

Security

This widget has no specific security concern. Refer to delite/FormValueWidget documentation for general security advice on this base class.

Browser Support

This widget supports all supported browsers without any degraded behavior.