Skip to main content
Neural UIv2.0.0Documentation
View v1 GitHub

Rating

Collect a nullable rating in full or half-star steps.

Category
Forms and selection
Import
@neural-ui/core/rating
Selector
neu-rating
import { NeuRatingComponent } from '@neural-ui/core/rating';

Usage

The model is number | null. stars sets the scale and step accepts 1 or 0.5. Activating the selected option again clears the rating to null; the application can also clear it directly. Use readonly to present an existing rating without allowing edits.

Examples

Interact with the example and open Code for its complete implementation.

Examples

Use the arrow keys for half-star steps. The value remains a number; null means no rating.

Try and configure

Change the controls and try the live preview. Expand the application value or event to inspect its real data; the generated template stays with the configurator.

Try and configure

Live preview

Generated template: the options above. The Code tab contains the imports and state.

template.html
<neu-rating
  [(value)]="number"
  [stars]="5"
  [step]="1"
  [label]="'Your rating'"
/>

Signal Forms

Bind FormField once to the component; the field owns value and validation. The schema requires a non-empty value. Leave the control to mark it touched, then reset the field to clear both value and interaction state.

Signal Forms guide

Signal Forms

Valid: false

Value and events

Use [(value)] or [value] with (valueChange), not both. The model synchronizes application state; other Outputs communicate their documented events. touch reports leaving/visiting the control, not a new value.

Accessibility and keyboard

Name the rating group with label or ariaLabel. The selected option is the tab stop; arrow keys change the rating without tabbing through every star. Home/End reaches the first or last option. Space/Enter activates an option and clears it when already selected. readonly keeps the value available without allowing edits.

Key
Action
Tab Enters the group at the selected rating, or its first option.
Arrow keys Selects the next or previous option; horizontal direction follows RTL.
Home / End Selects the first option or the maximum rating.
Space / Enter Activates the focused option; activating the current rating clears it.

API

Inputs, models and Outputs come from the pinned Core contract. Click named types to open their definitions. This component has no public template slots.

Inputs

Configure the component with [property]="value". Your application supplies these values; the component does not replace the state you pass in.

Name
Type
Default
Template binding
Description
ariaDescribedBystring''[ariaDescribedBy]IDs of elements describing the control, separated by spaces.
ariaLabelstring''[ariaLabel]Accessible name when no visible label is available.
dirtybooleanfalse[dirty]Form state indicating that the user has changed the value.
disabledbooleanfalse[disabled]Prevents user interaction.
errorsreadonly ValidationError.WithOptionalFieldTree[][][errors]Validation errors supplied by the form or the application.
hiddenbooleanfalse[hidden]Hides the control according to the form state.
inputIdstringinject(NeuIdGenerator).getId('neu-rating-')Derived default[inputId]Stable identifier of the native control; automatically generated when omitted.
invalidbooleanfalse[invalid]Displays the invalid state; it does not add a validation rule.
labelstring''[label]Visible label and accessible name of the control.
namestring''[name]Name associated with the native form control.
pendingbooleanfalse[pending]Form state indicating that asynchronous validation is pending.
readonlybooleanfalse[readonly]Keeps the control focusable and readable without accepting edits.
requiredbooleanfalse[required]Marks the field as required; use a form validator to enforce it.
starsnumber5[stars]Number of stars in the rating scale.
step1 | 0.51[step]1 for full stars or 0.5 for half stars.
touchedbooleanfalse[touched]Form state indicating that the control has been visited.

Models

A model supports [(property)]="signal" or the [property] and (propertyChange) pair. Choose one form, not both.

Name
Type
Default
Template binding
Description
valuenumber | nullnull[(value)]Committed number or null for an empty value; synchronized through valueChange.

Outputs

Listen to an event with (event)="handler($event)". The table explains the data your handler receives and how to use it.

Name
Payload
Template binding
Description
touchvoid(touch)="onTouch($event)"Notifies the form that the control has been touched; not a value change.

Templates

ng-content projects content into the component. TemplateRef inputs receive a template; ng-template directives identify templates with a typed context. A directive shared by an entrypoint is not necessarily a slot of this component.

This component does not expose content projection or public customization templates.

Styles and tokens

Load Core styles once. Use the public tokens below for local customization or a preset for application-wide changes. Keep labels, focus, selected options and disabled states readable in both light and dark themes.

Specific tokens

This component uses shared theme tokens rather than dedicated component hooks.

Shared tokens used

Override these on a local wrapper to affect this example. An override on :root affects other components that use the same token.

Token
Purpose here
Other impact
Default / fallback
--neu-focus-ring Normal keyboard-focus ring Shared by other Core consumers; scope the override. 0 0 0 var(--neu-focus-ring-width) rgba(0, 122, 255, 0.15)
--neu-text-muted Secondary labels and supporting content Shared by other Core consumers; scope the override. #475569
--neu-font-sans Text typography Shared by other Core consumers; scope the override. 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif
--neu-radius-sm Corner radius Shared by other Core consumers; scope the override. 6px
--neu-warning-text Inherited theme value used by this component Shared by other Core consumers; scope the override. #92400e