A rating component that allows users to view and provide ratings using customizable symbols. It supports fractional values, hover previews, keyboard navigation, single-selection mode, and integrates with forms as a number input.
- Element
-
igc-rating
- Slots
-
symbol— Slot for projecting custom rating symbol elements. When used, the number of symbols determines the `max` value. -
value-label— Renders content after the symbols, such as the value as text.
- CSS Parts
-
base— The main wrapper which holds the symbols and the value label. -
label— The label of the rating. -
value-label— The wrapper of the `value-label` slot. -
symbols— A wrapper for all rating symbols. -
symbol— The part of the encapsulated default symbol. -
full— The part of the encapsulated full symbols. -
empty— The part of the encapsulated empty symbols.
Example
<!-- Basic rating -->
<igc-rating value="3" max="5" label="Rate this product"></igc-rating> Properties
Section titled "Properties"allowReset
Section titled "allowReset"Whether to reset the rating when the user selects the same value.
allowReset: boolean = false Defined in src/components/rating/rating.ts:292
disabled
Section titled "disabled"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
Whether the control is disabled. A disabled control is not validated, and the form does not submit its value.
disabled: boolean Defined in src/internals/mixins/forms/types.ts:35
hoverPreview
Section titled "hoverPreview"Whether to show a preview of the value when hovering over the symbols.
hoverPreview: boolean = false Defined in src/components/rating/rating.ts:254
invalid
Section titled "invalid"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
Whether the control shows the invalid state. It changes only the visual state, not the validity.
invalid: boolean Defined in src/internals/mixins/forms/types.ts:43
Optional label
Section titled "label"The label of the control.
label: string Defined in src/components/rating/rating.ts:216
The maximum value for the rating.
With projected symbols, the maximum value is the number of symbols. A maximum below the value also lowers the value.
max: number = 5 Defined in src/components/rating/rating.ts:192
Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
The name of the control, submitted with the form data.
name: string Defined in src/internals/mixins/forms/types.ts:49
readOnly
Section titled "readOnly"Whether the rating is read-only. A read-only rating shows its value but ignores user input.
readOnly: boolean = false Defined in src/components/rating/rating.ts:264
single
Section titled "single"Whether only the symbol at the value is full, instead of all symbols up
to it. It also sets step to 1 and rounds the value up.
single: boolean = false Defined in src/components/rating/rating.ts:283
The minimum value change allowed.
Valid values are in the interval between 0.001 and 1 inclusive. The component clamps a value outside of the interval to the closest bound. In single selection mode, the step is always 1.
step: number = 1 Defined in src/components/rating/rating.ts:209
Optional valueFormat
Section titled "valueFormat"The format of the aria-valuetext of the rating. {0} stands for the
value and {1} for the maximum value.
Use it for screen readers and for localization.
valueFormat: string Defined in src/components/rating/rating.ts:226
tagName
Section titled "tagName"The tagName read-only property of the Element interface returns the tag name of the element on which it's called.
tagName: "igc-rating" = 'igc-rating' Defined in src/components/rating/rating.ts:115
Accessors
Section titled "Accessors"defaultValue
Section titled "defaultValue"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
get defaultValue(): any Defined in src/internals/mixins/forms/types.ts:158
The default value of the control. A form reset restores the value to it.
While the value is unchanged since the start or the last form reset, a new
default also sets the value. The value attribute also sets it.
set defaultValue(value: unknown): void Defined in src/internals/mixins/forms/types.ts:158
Parameters
- value:
unknown
Returns void
Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
The form that the control is associated with, or null.
get form(): HTMLFormElement | null Defined in src/internals/mixins/forms/types.ts:52
Returns HTMLFormElement | null
validationMessage
Section titled "validationMessage"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
The validation message of the control. It is empty when the control is valid.
get validationMessage(): string Defined in src/internals/mixins/forms/types.ts:61
Returns string
validity
Section titled "validity"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
The validity state of the control.
get validity(): ValidityState Defined in src/internals/mixins/forms/types.ts:55
Returns ValidityState
value
Section titled "value"get value(): any Defined in src/components/rating/rating.ts:236
The value of the rating, clamped between 0 and max.
set value(number: number): void Defined in src/components/rating/rating.ts:236
Parameters
- number:
number
Returns void
willValidate
Section titled "willValidate"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
Whether the control is a candidate for constraint validation.
get willValidate(): boolean Defined in src/internals/mixins/forms/types.ts:64
Returns boolean
Methods
Section titled "Methods"Removes focus from the rating.
blur(): void Defined in src/components/rating/rating.ts:490
Returns void
checkValidity
Section titled "checkValidity"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
Checks validity and emits invalid when the control is invalid. Returns
true when the control is valid.
checkValidity(): boolean Defined in src/internals/mixins/forms/types.ts:134
Returns boolean
focus
Section titled "focus"Sets focus on the rating. A disabled rating does not take the focus.
focus(options: FocusOptions): void Defined in src/components/rating/rating.ts:481
Parameters
- options:
FocusOptions
Returns void
reportValidity
Section titled "reportValidity"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
Checks validity. As for a native control, an invalid control emits
invalid and takes the focus. It shows its own validation messages, not
the message of the browser. Returns true when the control is valid.
reportValidity(): boolean Defined in src/internals/mixins/forms/types.ts:141
Returns boolean
setCustomValidity
Section titled "setCustomValidity"Inherited from: FormAssociatedMixin( EventEmitterMixin<IgcRatingComponentEventMap>(LitElement) )
Sets a custom validation message. The control is invalid while the message is not empty. An empty string removes the custom error.
setCustomValidity(message: string): void Defined in src/internals/mixins/forms/types.ts:147
Parameters
- message:
string
Returns void
stepDown
Section titled "stepDown"Decrements the value of the control by n steps multiplied by
the step factor.
stepDown(n: number): void Defined in src/components/rating/rating.ts:475
Parameters
- n:
number
Returns void
stepUp
Section titled "stepUp"Increments the value of the control by n steps multiplied by the
step factor.
stepUp(n: number): void Defined in src/components/rating/rating.ts:467
Parameters
- n:
number