# @salmonui/inputs/rating API reference

> 5 exported symbols of @salmonui/inputs/rating: 1 component, 1 interface and 3 types.

Canonical: https://salmonui.dev/docs/reference/inputs/rating

```ts
import { … } from '@salmonui/inputs/rating';
```

## Components

### Rating

Kind: component

Page: https://salmonui.dev/docs/reference/inputs/rating/Rating

```ts
function Rating(props: RatingProps): ReactNode;
```

Rating: one native radio per step (two per item with
`precision="half"`) named by `localeText.item`, inside a
`<fieldset role="radiogroup">` named by `label`. Arrow keys are the
browser's radio keys (mirrored in RTL); hover preview is CSS. Read-only
`'quarter'` / `'exact'` precision renders one `role="img"` with a clipped
fill. `ref` is the root element.

Props: [`RatingProps`](https://salmonui.dev/docs/reference/inputs/rating/RatingProps) (its members are the props)

## Interfaces

### RatingProps

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/rating/RatingProps

```ts
interface RatingProps extends FieldCommonProps {
    readonly value?: number | undefined;
    readonly defaultValue?: number | undefined;
    readonly onValueChange?: ((value: number, details: RatingChangeDetails) => void) | undefined;
    readonly count?: number | undefined;
    readonly min?: number | undefined;
    readonly precision?: 'full' | 'half' | 'quarter' | 'exact' | undefined;
    readonly clearable?: boolean | undefined;
    readonly highlightSelectedOnly?: boolean | undefined;
    readonly showLabel?: boolean | undefined;
    readonly labelPlacement?: 'top' | 'bottom' | 'start' | 'end' | undefined;
    readonly renderLabel?: ((ctx: {
        readonly value: number;
        readonly count: number;
    }) => ReactNode) | undefined;
    readonly icon?: ReactNode;
    readonly emptyIcon?: ReactNode;
    readonly renderItem?: ((ctx: {
        readonly index: number;
        readonly state: RatingItemState;
        readonly fill: number;
    }) => ReactNode) | undefined;
    readonly showTooltip?: boolean | undefined;
    readonly renderTooltip?: ((ctx: {
        readonly value: number;
        readonly count: number;
    }) => ReactNode) | undefined;
    readonly onHoverChange?: ((value: number | null) => void) | undefined;
    readonly name?: string | undefined;
    readonly form?: string | undefined;
    readonly required?: boolean | undefined;
    readonly disabled?: boolean | undefined;
    readonly readOnly?: boolean | undefined;
    readonly localeText?: RatingLocaleText | undefined;
    readonly id?: string | undefined;
    readonly dir?: 'ltr' | 'rtl' | 'auto' | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly classNames?: {
        readonly label?: string;
        readonly items?: string;
        readonly item?: string;
        readonly value?: string;
        readonly description?: string;
        readonly error?: string;
    } | undefined;
    readonly ref?: Ref<HTMLElement> | undefined;
}
```

Members (36):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `label` | `label?: ReactNode;` | optional, inherited |  |
| `description` | `description?: ReactNode;` | optional, inherited |  |
| `errorMessage` | `errorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) \| ReactNode;` | optional, inherited | Error text (or a function of the errors) shown while the field is invalid. |
| `invalid` | `invalid?: boolean;` | optional, inherited | Forces the error state. |
| `validation` | `validation?: FieldValidation;` | optional, inherited | Rules in the Data Grid vocabulary. |
| `validateOn` | `validateOn?: ValidateOn;` | optional, inherited | When errors appear; default the `Form`'s, else `'blur'`. |
| `size` | `size?: FieldSize;` | optional, inherited | Metric set. Default `'md'`. |
| `value` | `readonly value?: number \| undefined;` | optional |  |
| `defaultValue` | `readonly defaultValue?: number \| undefined;` | optional | Default `min`. |
| `onValueChange` | `readonly onValueChange?: ((value: number, details: RatingChangeDetails) => void) \| undefined;` | optional |  |
| `count` | `readonly count?: number \| undefined;` | optional | Number of items. Default 5. |
| `min` | `readonly min?: number \| undefined;` | optional | Lowest value a selection can set; the cleared value. Default 0. |
| `precision` | `readonly precision?: 'full' \| 'half' \| 'quarter' \| 'exact' \| undefined;` | optional | Step: `'full'` or `'half'` while editing; `'quarter'` and `'exact'` only with `readOnly` (a `role="img"` display). Default `'full'`. |
| `clearable` | `readonly clearable?: boolean \| undefined;` | optional | Shows a clear button while the value is above `min`. |
| `highlightSelectedOnly` | `readonly highlightSelectedOnly?: boolean \| undefined;` | optional | Fills only the selected item. |
| `showLabel` | `readonly showLabel?: boolean \| undefined;` | optional | Shows the value next to the items. |
| `labelPlacement` | `readonly labelPlacement?: 'top' \| 'bottom' \| 'start' \| 'end' \| undefined;` | optional | Where the value label sits. Default `'end'`. |
| `renderLabel` | `readonly renderLabel?: ((ctx: {     readonly value: number;     readonly count: number; }) => ReactNode) \| undefined;` | optional |  |
| `icon` | `readonly icon?: ReactNode;` | optional | Filled icon. Default a star. |
| `emptyIcon` | `readonly emptyIcon?: ReactNode;` | optional | Empty icon. Default `icon` (drawn in the empty color). |
| `renderItem` | `readonly renderItem?: ((ctx: {     readonly index: number;     readonly state: RatingItemState;     readonly fill: number; }) => ReactNode) \| undefined;` | optional | Replaces both icons of an item. |
| `showTooltip` | `readonly showTooltip?: boolean \| undefined;` | optional | Shows a value bubble over the hovered or focused step. |
| `renderTooltip` | `readonly renderTooltip?: ((ctx: {     readonly value: number;     readonly count: number; }) => ReactNode) \| undefined;` | optional |  |
| `onHoverChange` | `readonly onHoverChange?: ((value: number \| null) => void) \| undefined;` | optional | The step under the pointer, `null` when it leaves. Bound listeners only when given; no state. |
| `name` | `readonly name?: string \| undefined;` | optional | Submitted name. Without it the radios share a generated name and are not submitted. |
| `form` | `readonly form?: string \| undefined;` | optional |  |
| `required` | `readonly required?: boolean \| undefined;` | optional |  |
| `disabled` | `readonly disabled?: boolean \| undefined;` | optional |  |
| `readOnly` | `readonly readOnly?: boolean \| undefined;` | optional | Display only: radios stay focusable but ignore changes; `'quarter'` / `'exact'` render a `role="img"`. |
| `localeText` | `readonly localeText?: RatingLocaleText \| undefined;` | optional |  |
| `id` | `readonly id?: string \| undefined;` | optional |  |
| `dir` | `readonly dir?: 'ltr' \| 'rtl' \| 'auto' \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `classNames` | `readonly classNames?: {     readonly label?: string;     readonly items?: string;     readonly item?: string;     readonly value?: string;     readonly description?: string;     readonly error?: string; } \| undefined;` | optional | Part classes: `root` is `className`; `label`, `items`, `item`, `value`, `description`, `error`. |
| `ref` | `readonly ref?: Ref<HTMLElement> \| undefined;` | optional | The root element (`<fieldset>`, or `<div>` for the image display). |

## Types

### RatingChangeDetails

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/rating/RatingChangeDetails

```ts
type RatingChangeDetails = ChoiceChangeDetails<'select' | 'clear' | 'reset'>;
```

Second argument of `onValueChange`: `'select'` (click, arrow keys), `'clear'` (clear button) or `'reset'` (form reset).

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `source: "api" \| PressSource;` | inherited |  |
| `reason` | `reason: "clear" \| "reset" \| "select";` | inherited |  |

### RatingItemState

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/rating/RatingItemState

```ts
type RatingItemState = 'full' | 'half' | 'empty';
```

Fill state of one item.

### RatingLocaleText

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/rating/RatingLocaleText

```ts
type RatingLocaleText = FieldValidationText & {
    readonly item?: string;
    readonly clear?: string;
};
```

User-visible strings. `item` names each radio and the read-only image
(`{0}` value, `{1}` count; default `'{0} of {1} stars'`); `clear` names the
clear button.

Members (19):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `validationCreditcard` | `validationCreditcard?: string;` | optional, inherited |  |
| `validationDate` | `validationDate?: string;` | optional, inherited |  |
| `validationDateIso` | `validationDateIso?: string;` | optional, inherited |  |
| `validationDigits` | `validationDigits?: string;` | optional, inherited |  |
| `validationEmail` | `validationEmail?: string;` | optional, inherited |  |
| `validationMax` | `validationMax?: string;` | optional, inherited |  |
| `validationMaxLength` | `validationMaxLength?: string;` | optional, inherited |  |
| `validationMin` | `validationMin?: string;` | optional, inherited |  |
| `validationMinLength` | `validationMinLength?: string;` | optional, inherited |  |
| `validationNumber` | `validationNumber?: string;` | optional, inherited |  |
| `validationPattern` | `validationPattern?: string;` | optional, inherited |  |
| `validationRange` | `validationRange?: string;` | optional, inherited |  |
| `validationRangeLength` | `validationRangeLength?: string;` | optional, inherited |  |
| `validationRequired` | `validationRequired?: string;` | optional, inherited |  |
| `validationTel` | `validationTel?: string;` | optional, inherited |  |
| `validationUrl` | `validationUrl?: string;` | optional, inherited |  |
| `validationValidate` | `validationValidate?: string;` | optional, inherited |  |
| `item` | `item?: string;` | optional, inherited |  |
| `clear` | `clear?: string;` | optional, inherited |  |
