salla-rating-stars

Shows a five star rating, either as a read-only display of a score or as an input the customer clicks to pick a rating.

Shows a five star rating, either as a read-only display of a score or as an input the customer clicks to pick a rating. Use the read-only form on product cards and review lists, and the editable form in review forms.

With a value and without editable, it displays that many filled stars (plus the review count when reviews is above 0). With no value, or with editable, it renders five buttons and a hidden input named by name, so the picked rating (1 to 5) is submitted with the surrounding form. In editable mode a given value is pre-selected until the customer picks one. The star buttons set aria-pressed on the chosen star. The text label is hidden from assistive technology while it is empty.

Use it

In HTML or JSX, use the tag <salla-rating-stars> with the Attribute names below. In React, the wrapper takes the Property names (camelCase).

import { SallaRatingStars } from '@salla.sa/twilight-components-react/rating-stars';

Client-only. On the server this wrapper renders a placeholder (a skeleton, or nothing), and the real component mounts in the browser. Do not rely on it for content that search engines must see.

Try it

web-components/salla-rating-stars

Example

import { SallaRatingStars } from '@salla.sa/twilight-components-react/rating-stars';

export function Example() {
  return (
    <SallaRatingStars value={4} reviews={120} size="small" />
  );
}
import { SallaRatingStars } from '@salla.sa/twilight-components-react/rating-stars';

export function Example() {
  return (
    <form>
      <SallaRatingStars name="rating" withLabel />
    </form>
  );
}

Properties

PropertyAttributeDescriptionTypeDefault
editableeditableMakes the rating an input the customer can click. Without it, the stars are read-only whenever value is set.booleanfalse
labelBeforeStarslabel-before-starsPlaces the description label before the stars instead of after. Only has an effect together with with-label.booleanfalse
namenameName of the hidden input that holds the picked rating (1 to 5) in the editable form.string'rating'
reviewsreviewsNumber of reviews shown in brackets after the stars. Nothing is shown when it is 0. Only used in read-only mode.number0
sizesizeSize of the stars: large, medium, small or mini. It is added as a CSS class (s-rating-stars-<size>) on each star."large" | "medium" | "mini" | "small"'medium'
tagtagOnly switches the CSS class of the text label between s-rating-stars-label (true) and s-rating-stars-label-without-tag (false), so a theme can style them differently.booleantrue
valuevalueThe rating, from 1 to 5. In read-only mode this many stars are filled. With editable it is the pre-selected rating. Also picks the text label when with-label is set.number
withLabelwith-labelShows a text label (such as poor, good or excellent) for the current or hovered rating.boolean

Used inside: <salla-comment-factors>, <salla-comment-item>, <salla-filters-widget>, <salla-rating-modal>, <salla-rating-modal-v2>, <salla-review-order-item>, <salla-reviews>, <salla-reviews-summary>.

On this page