Skip to content

RatingField

RatingField provides a Cratis-owned star-rating radio group with labeled options bound to a number property.

The excerpt assumes SubmitReview is a generated command proxy with the bound properties, and visible / setVisible is component state.

import { CommandDialog } from '@cratis/components/CommandDialog';
import { RatingField } from '@cratis/components/CommandForm';
<CommandDialog<SubmitReview>
command={SubmitReview}
title='Review'
visible={visible}
onSuccess={() => setVisible(false)}
onCancel={() => setVisible(false)}
>
<RatingField<SubmitReview> value={(c) => c.rating} title='Rating' stars={5} />
</CommandDialog>;
PropTypeDefaultDescription
value(instance: TCommand) => unknown—Required. Accessor that returns the bound property from the command instance. Pass the command type as the generic parameter for full type safety.
starsnumber5Number of stars to display.
namestringgeneratedOptional native radio-group name. Every star in the component shares one name.
starAriaLabel(starValue: number) => string"1 star", "2 stars", …Builds the accessible name for each star, from the 1-based star value. Override to localize.
classNamestring—Extra CSS class name.
ptcomponent-specific parts—Cratis-owned HTML attributes for stable parts.
ptOptionsobject—Legacy compatibility prop; ignored.
unstyledbooleanfalseLegacy compatibility prop; ignored.

Every field also accepts Arc’s shared field props, such as title, description, initialValue, and noInitialValue, and the accessibility props id, aria-label, and aria-describedby. See Accessible names and validation errors.

  • Shows 0 (no rating selected) while the bound property is unset. See Field defaults and command values.
  • The bound value is the selected star count (1–stars).
  • Stars use native arrow-key radio navigation with one tab stop.
  • Validation state is reflected through aria-invalid and data-invalid.