Skip to content

BbRating

Collects scalar ratings through interactive icons.

import { BbRating } from 'bitboss-ui';

On this page

Props

NameTypeDefaultDescription
autofocusBooleanish | undefined-

Sets autofocus on page load.

clearableboolean | undefinedfalse

Allows clearing the selected rating by clicking the current value.

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

See example
compactboolean | undefinedfalse

Sets the component in a compact state.

descriptionstring | undefined-

Descriptive text displayed below the label and above the input. Unlike the hint it is always visible, and it is linked to the input via 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
directionInputDirection | undefined-

Direction of the layout of the component. Can either be a predefined value or a pattern separated by a space like xx xxxxx.

disabledboolean | undefinedfalse

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
errorsstring | string[] | undefined-

Can be a string or an array of string containing the messages to display. They render in an aria-live="polite" region (announced when they appear) and, while the list is non-empty, are referenced FIRST from the control's aria-describedby, so the reason the field is invalid is re-read whenever the control regains focus.

Applies to the whole fieldset rather than to one star. Clear it as soon as a value is picked — a form that keeps shouting after the user complied is a form people stop reading.

See example
hasErrorsboolean | undefinedfalse

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

hasWarningsboolean | undefinedfalse

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

hideLegendboolean | undefinedfalse

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
hintstring | undefined-

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

idstring | undefined-

The identifier of the component.

inputPosition"left" | "center" | "right" | undefined"left"

Sets the alignment of the input. Since inputs are inline block they can be aligned just as text can.

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.

See example
legendrequiredstring-

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"outside" | "inside" | undefined-

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.

See example
legendPosition"left" | "center" | "right" | undefined-

Sets the text alignment of the legend.

modelValuerequirednumber | null-

Used by v-model.

namestring | undefined-

Defines the name of the star radio inputs. Optional: the stars live inside a single component instance, so an omitted name falls back to a generated one that groups them correctly on its own. Pass a name only when the value has to be submitted under a known key by a native (non-JS) form post.

Optional in v3, required in v2. Omitted, the component generates a group name that is unique and stable for the instance, so two ratings on one page cannot bleed into each other. Pass it when a native form post needs the value under a key you chose.

See example
persistentHintboolean | undefinedfalse

Keeps the hint displayed.

ptPtMap<BbRatingPtPart, BbRatingPtState> | undefined-

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

pt:descriptionPtValue | undefined-
pt:description:disabledPtValue | undefined-
pt:description:errorsPtValue | undefined-
pt:description:has-valuePtValue | undefined-
pt:description:readonlyPtValue | undefined-
pt:description:selectedPtValue | undefined-
pt:description:warningsPtValue | undefined-
pt:hintPtValue | undefined-
pt:hint:disabledPtValue | undefined-
pt:hint:errorsPtValue | undefined-
pt:hint:has-valuePtValue | undefined-
pt:hint:readonlyPtValue | undefined-
pt:hint:selectedPtValue | undefined-
pt:hint:warningsPtValue | undefined-
pt:itemPtValue | undefined-
pt:item:disabledPtValue | undefined-
pt:item:errorsPtValue | undefined-
pt:item:has-valuePtValue | undefined-
pt:item:readonlyPtValue | undefined-
pt:item:selectedPtValue | undefined-
pt:item:warningsPtValue | undefined-
pt:labelPtValue | undefined-
pt:label:disabledPtValue | undefined-
pt:label:errorsPtValue | undefined-
pt:label:has-valuePtValue | undefined-
pt:label:readonlyPtValue | undefined-
pt:label:selectedPtValue | undefined-
pt:label:warningsPtValue | undefined-
pt:messagePtValue | undefined-
pt:message:disabledPtValue | undefined-
pt:message:errorsPtValue | undefined-
pt:message:has-valuePtValue | undefined-
pt:message:readonlyPtValue | undefined-
pt:message:selectedPtValue | undefined-
pt:message:warningsPtValue | undefined-
pt:rootPtValue | undefined-
pt:root:disabledPtValue | undefined-
pt:root:errorsPtValue | undefined-
pt:root:has-valuePtValue | undefined-
pt:root:readonlyPtValue | undefined-
pt:root:selectedPtValue | undefined-
pt:root:warningsPtValue | undefined-
readonlyboolean | undefinedfalse

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
requiredboolean | undefinedfalse

Sets the input as required.

Applies to the fieldset, so it is satisfied by any star. Combine with errors for the message; the browser will not write one for you.

See example
reverseboolean | undefinedfalse

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

sizenumber | ({ size?: any; } & string) | keyof Sizes | undefined'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
starsnumber | undefined5

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
warningsstring | string[] | undefined-

Warning messages to display beneath the field, in their own aria-live region and amber (--bb-text-warn). A string or array; a non-empty list implies the warning state. Errors suppress warnings when both are set. While displayed they are also referenced from the control's aria-describedby, after any errors and before the description/hint.

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.

NameTypeDescription
modelValuenumber | 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

NameTypeDescription
active(event: "active"): void
blur(event: "blur", event: FocusEvent): void
change(event: "change", event: Event): void
click(event: "click", event: MouseEvent): void
focus(event: "focus", event: FocusEvent): void
inactive(event: "inactive"): void
input(event: "input", event: Event): void
keydown(event: "keydown", event: KeyboardEvent): void
mousedown(event: "mousedown", event: MouseEvent): void
mouseup(event: "mouseup", event: MouseEvent): void
update:modelValue(event: "update:modelValue", value: number | null): void

Slots

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

NameTypeDescription
appendobject

Content rendered after the row of rating stars.

Where the precise figure and the sample size go, because there are no half stars: a 4.6 average fills four, so round for the glyphs and print the decimal as text.

See example
descriptionBbRatingDescriptionSlotProps

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

iconBbRatingIconSlotProps

Replaces the default star SVG for each rating option.

Replaces the star glyph 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.

See example
legendBbRatingLegendSlotProps

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

prependobject

Content rendered before the row of rating stars.

Changes from v2

Props removed or renamed in 3.0. If you are coming from v2, the answer is here.

  • colorremovedfails silently
  • hasWarninghasWarningsfails silently