Skip to content

BbRating

Collects scalar ratings through interactive icons.

import { BbRating } from 'bitboss-ui';

On this page

Props

NameDescription
autofocus Type: Booleanish

Focuses the field when it mounts (a dialog already open included), unless the user is typing in another field.

clearable Type: booleanDefaultfalse

Allows clearing the selected rating: click the selected star, or Space on it.

Adds the only way back to unrated, since a radio group cannot be un-picked: click the selected star again, or press Space on it (Delete and Backspace do nothing). Neither gesture is discoverable, so pair it with a hint, and expect null, never 0.

See example
compact Type: boolean

Compact density. Swaps --bb-label-spacing-y for --bb-label-spacing-y-compact, so tune a compact group's label gap with the -compact token, not the base one.

description Type: string

Text between the label and the input. Unlike the hint it is always visible; it joins the input's aria-describedby after any errors / warnings, before the hint.

Always visible, above the stars. The place for what the scale means before anyone picks a point on it.

See example
disabled Type: booleanDefaultfalse

Disables the component.

Takes the group out of the tab order, so the score is missing entirely for someone navigating by keyboard. Prefer readonly for a score the user may inspect.

See example
errors Type: string | string[]

Error messages under the field, a string or array, in an aria-live="polite" region and first in the control's aria-describedby, so they are re-read when it regains focus.

Applies to the whole fieldset rather than to one star. Inside a BbForm the rule messages land here by themselves; set it by hand only outside one, and clear it as soon as a value is picked.

See example
formless Type: booleanDefaultfalse

Keep this control out of the enclosing BbForm entirely: not submitted, not dirty, not reset, not validated. For a control that is not form data (a filter, a "show advanced" switch).

hasErrors Type: booleanDefaultfalse

Define if the component should be in an error state. It usually attaches a CSS class for styling purposes.

hasWarnings Type: booleanDefaultfalse

Define if the component should be in a warning state. Same chrome as errors with --bb-warn; errors take priority.

hideLegend Type: booleanDefaultfalse

Visually hides the legend of the fieldset while maintaining accessibility.

Keeps the accessible name and removes only the visible text, which is what a score under a product title wants. legend itself is required by the type and is the only name the group has.

See example
hint Type: string

Text box to be displayed near the input, usually to indicate instructions.

id Type: string

Prefix for the ids of each option's input and of the label, description and message. Generated when omitted.

inputAlign Type: FieldCrossAlign

Vertical position of the control in a side-by-side row; not inputPosition, the horizontal one. Omitted, 'top'.

inputPosition Type: "end" | "start" | "center" | "left" | "right"Default'start'

Alignment of the input in its column. 'start' / 'end' follow the page direction (the inline start is the left in a left-to-right page, the right in a right-to-left one); 'left' / 'right' stay physical; 'center' centres it. The default, 'start', follows the page direction.

Aligns the row of stars within its column. It was accepted, typed and documented in v2 and did nothing: the rules targeted a class this component never rendered. v3 repoints them, so a hand-rolled alignment workaround now fights the library and should be deleted.

labelAlign Type: FieldCrossAlign

Vertical position of the label block in a side-by-side row; not labelPosition, the horizontal one. Omitted, 'top'.

layout Type: Responsive<FieldLayout>

How label and input sit together: 'vertical', 'horizontal' (50/50), 'auto', 'label-fill', 'input-fill', a ratio like 'xx xxxxx', or a per-breakpoint map ({ default: 'vertical', md: 'xx xxxxx' }).

legend requiredType: string

Text content of the legend.

The family says label; this component says legend, because the control is a real <fieldset>. Same for legend-mode, hide-legend and legend-position.

See example
legendMode Type: "outside" | "inside"

Legend rendering mode. 'outside' renders the legend above the fieldset in the normal flow; 'inside' overlays the legend inside the fieldset border. Floating mode is not supported for rating groups.

Places the legend the way label-mode places a label elsewhere: outside above the stars, inside pinned in a bordered shell around them.

legendPosition Type: "end" | "start" | "center" | "left" | "right"Default'start'

Text alignment of the legend. 'start' / 'end' follow the page direction (the inline start is the left in a left-to-right page, the right in a right-to-left one); 'left' / 'right' stay physical; 'center' centres it. The default, 'start', follows the page direction.

modelValue Type: number | null

Used by v-model. A user picks whole stars; a readonly rating shows any value as it is (4.6 lights 60% of the fifth star).

name Type: string

Name of the star radio inputs. Optional: the stars live in one component instance, so an omitted name falls back to a generated one that groups them correctly. Pass one only when a native (non-JS) form post must submit the value under a known key.

The key of the value inside a BbForm and in a native form post. Omitted, the radios get a generated group name, unique to the instance, and a BbForm keys the value by the slugged legend; pass it whenever the value is submitted.

See example
persistentHint Type: booleanDefaultfalse

Keeps the hint displayed.

pt Type: (PtCompoundOf<"", { readonly parts: readonly ["root", "legend", "description", "message", "hint", "item"]; readonly states: readonly ["hasValue", "selected", "readonly", "disabled", "warnings", "errors"]; readonly wide: readonly ["hasValue", "readonly", "disabled", "warnings", "errors"]; readonly node: { readonly item: readonly ["selected"]; }; }> & { legend?: PtValue | undefined; root?: PtValue | undefined; "root:disabled"?: PtValue | undefined; "root:errors"?: PtValue | undefined; "root:warnings"?: PtValue | undefined; "root:readonly"?: PtValue | undefined; item?: PtValue | undefined; "item:disabled"?: PtValue | undefined; "item:selected"?: PtValue | undefined; description?: PtValue | undefined; message?: PtValue | undefined; hint?: PtValue | undefined; "description:disabled"?: PtValue | undefined; "description:errors"?: PtValue | undefined; "description:warnings"?: PtValue | undefined; "description:readonly"?: PtValue | undefined; "message:disabled"?: PtValue | undefined; "message:errors"?: PtValue | undefined; "message:warnings"?: PtValue | undefined; "message:readonly"?: PtValue | undefined; "hint:disabled"?: PtValue | undefined; "hint:errors"?: PtValue | undefined; "hint:warnings"?: PtValue | undefined; "hint:readonly"?: PtValue | undefined; "legend:disabled"?: PtValue | undefined; "legend:errors"?: PtValue | undefined; "legend:warnings"?: PtValue | undefined; "legend:readonly"?: PtValue | undefined; "legend:hasValue"?: PtValue | undefined; "root:hasValue"?: PtValue | undefined; "item:errors"?: PtValue | undefined; "item:warnings"?: PtValue | undefined; "item:readonly"?: PtValue | undefined; "item:hasValue"?: PtValue | undefined; "description:hasValue"?: PtValue | undefined; "message:hasValue"?: PtValue | undefined; "hint:hasValue"?: PtValue | undefined; })

Passthrough, object form: the same keys as the pt:* attributes without the prefix. See the pt:<part> row.

pt:<part> Type: PtValue

Passthrough, attribute form: one attribute per part, pt:<part>, and per part and state, pt:<part>:<state>. Parts: description, hint, item, legend, message, root. States: disabled, errors, hasValue, readonly, selected, warnings.

See example
readonly Type: booleanDefaultfalse

Sets the input in a readonly state.

Keeps the group focusable and exposes aria-readonly, and swallows the clear keys so a displayed score cannot be nudged to null. This is the read-only half of the component, not a disabled state.

See example
required Type: booleanDefaultfalse

Sets the input as required.

Applies to the fieldset, so any star satisfies it, and marks the legend unless the plugin's requiredAsterisk is off. Inside a BbForm the check is a rule; outside one, a plain <form> checks it on submit and shows the message as the rating's error.

See example
reverse Type: boolean

Reverses the layout. Applicable in every direction the order of the label and the input is swapped.

rules Type: RuleExpression<number | null>

vee-validate rules for this field. Only inside a BbForm.

Inside a BbForm, and keyed by name (else the slugged legend). Unrated is null, so a rule for "pick a star" refuses null, not 0.

See example
size Type: number | CssSize | keyof SizesDefault'md'

Defines the component size. Accepted values: - A key from the provided size map (keyof T), e.g. 'sm' | 'md' | 'lg' - A custom CSS size string (e.g. '20px', '1.5rem', '2em') - A number, typically interpreted as pixels by size parsers

The glyph size only — never the number of stars and never the value, both of which are stars. Takes a key from the shared scale or a CSS length.

See example
stars Type: numberDefault5

Maximum number of stars to render and maximum value of the component.

Sets the number of glyphs and the maximum value at once. Past ten or so a row of identical glyphs stops being countable at a glance; a BbSlider or a BbRadioGroup with real labels answers the same question better.

See example
validationLabel Type: string

The field's name in validation messages ({field}): "Email is not valid". Defaults to the label (or legend), then "This field"; never the name. Set it when the label is hidden or reads badly in a sentence (icon-only, a question). BbForm only.

validationMode Type: ValidationMode

When the field validates: aggressive (each change), balanced (on leave, then live while in error), lazy (on leave), submit-only, submit-live. Unset: the BbForm's validation-mode, then all.validationMode ('balanced'). BbForm only.

warnings Type: string | string[]

Warning messages under the field, a string or array: amber, in their own aria-live region and in the control's aria-describedby after the errors. Non-empty turns on the warning state; errors win when both are set.

The amber counterpart of errors, for a score that is accepted and worth a second look. Suppressed when errors are also set.

See example

v-model

Values kept in sync through v-model.

NameDescription
modelValue Type: number | null

number | null, always a whole number. null means unrated and is what clearable emits — storing it as 0 puts a real score into every average you compute later.

See example

Events

NameDescription
active Type: (value: number | null): void

Emitted when the rating becomes active (focus/click enters it), with the current value.

blur Type: (event: FocusEvent): void

Emitted when a star input loses focus. Forwards the original DOM FocusEvent.

change Type: (event: Event): void

Emitted when the selected rating changes. Forwards the original DOM Event.

click Type: (event: MouseEvent): void

Emitted when a star input receives a click. Forwards the original DOM MouseEvent.

focus Type: (event: FocusEvent): void

Emitted when a star input gains focus. Forwards the original DOM FocusEvent.

inactive Type: (value: number | null): void

Emitted when focus/click moves outside the rating after it was active, with the current value, whether or not it changed.

input Type: (event: Event): void

Emitted on native input events from the star inputs. Forwards the original DOM Event.

keydown Type: (event: KeyboardEvent): void

Emitted for keyboard interaction on a star input. Forwards the original DOM KeyboardEvent.

mousedown Type: (event: MouseEvent): void

Emitted when a pointing device button is pressed over a star input. Forwards the original DOM MouseEvent.

mouseup Type: (event: MouseEvent): void

Emitted when a pointing device button is released over a star input. Forwards the original DOM MouseEvent.

update:modelValue Type: (value: number | null): void

Emitted with the selected rating (1 to stars) when clicked. Emits null only when clearable is enabled and the already-selected star is clicked (or gets Space).

value-commit Type: (value: number | null): void

Emitted once the user finishes changing the value, after update:modelValue, with the same value: each pick (arrow keys included), and clear. Never for a value you set or a coherence correction.

The hook for saving: each pick, arrow keys included, and clear. Never for a value your code sets.

See example

Slots

The listed properties are the ones exposed to the slot scope.

NameDescription
append Type: object

Content rendered after the row of rating stars.

Where the figure and the sample size go. Pass a read-only average as it is: 4.6 fills four stars and 60% of the fifth.

See example
description Type: BbRatingDescriptionSlotProps

Replaces the description text. Provided alone (no description prop) it still renders the description region and wires it into aria-describedby.

hint Type: BbRatingDescriptionSlotProps

Replaces the hint text; alone it still renders the row. May hold an action.

icon Type: BbRatingIconSlotProps

Replaces the default star SVG for each rating option.

Replaces the star icon and nothing else. size arrives already resolved into a CSS length string ('24px', not 24), so pass it straight to BbIcon; arithmetic on it produces NaN silently. checked is true on every lit star, not only the picked one. Colour still goes through --accent / --empty on the root, never a colour class on the icon.

See example
legend Type: BbRatingLegendSlotProps

Replaces the default fieldset legend text rendered above the rating stars.

prepend Type: object

Content rendered before the row of rating stars.

Renamed and removed

Names from v2 and from earlier 3.0 betas that no longer work, and what to write instead.

  • colorremovedfails silently
  • directionlayoutfails silently
  • hasWarninghasWarningsfails silently
  • pt:labelpt:legendfails silently
  • validateOnvalidationModefails silently

    An array of events became one mode (aggressive | balanced | lazy | submit-only | submit-live). The old defaults (['blur'], ['inactive'], a toggle's ['update:modelValue', 'change', 'blur']) are balanced, the new default: delete the prop. A text field on ['update:modelValue'] is validation-mode="aggressive". Set it once on <BbForm validation-mode> instead of per field.

  • vidremovedfails silently

    A display name (v2: vid="Email address") is now validation-label; a field path (3.0 betas: vid="address.city") is now name (brackets for a native post: address[city]). check --fix picks by the value.