Rating
Choose, change, or clear one score on an ordered rating scale.
Usage
Five star
Choose and clear a score on a five-point rating scale.
Choose and clear a score on a five-point rating scale.
<!-- Rating / Five Star -->
<script setup lang="ts">
import { RatingRoot, RatingItem, RatingIndicator, RatingClear } from '@sectile/vue/rating'
const ratings = ['1', '2', '3', '4', '5']
</script>
<template>
<RatingRoot :items="ratings" default-value="4" :clearable="true">
<RatingItem v-for="value in ratings" :key="value" :value="value">
★<RatingIndicator />
</RatingItem>
<RatingClear>Clear rating</RatingClear>
</RatingRoot>
</template>Required
Require one value to remain selected or one section to remain expanded.
Require one value to remain selected or one section to remain expanded.
<!-- Rating / Required -->
<script setup lang="ts">
import { RatingRoot, RatingItem, RatingIndicator, RatingClear } from '@sectile/vue/rating'
const ratings = ['1', '2', '3', '4', '5']
</script>
<template>
<RatingRoot :items="ratings" default-value="4" :clearable="true">
<RatingItem v-for="value in ratings" :key="value" :value="value">
★<RatingIndicator />
</RatingItem>
<RatingClear>Clear rating</RatingClear>
</RatingRoot>
</template>Controlled
Let the parent own the current value and apply accepted changes back to the component.
Let the parent own the current value and apply accepted changes back to the component.
<!-- Rating / Controlled -->
<script setup lang="ts">
import { RatingRoot, RatingItem, RatingIndicator, RatingClear } from '@sectile/vue/rating'
const ratings = ['1', '2', '3', '4', '5']
</script>
<template>
<RatingRoot :items="ratings" default-value="4" :clearable="true">
<RatingItem v-for="value in ratings" :key="value" :value="value">
★<RatingIndicator />
</RatingItem>
<RatingClear>Clear rating</RatingClear>
</RatingRoot>
</template>API
Vue package: @sectile/vue/rating
RatingRootRatingItemRatingIndicatorRatingClear
Props
RatingRootProps
as- Type
PrimitiveAsDefault'div'Element or component rendered for this part.
asChild- Type
booleanDefaultfalseWhether to merge this part into its single child instead of rendering a wrapper.
clearable- Type
booleanDefaultfalseWhether the current selection can be cleared.
defaultValue- Type
stringDefault''Initial value used when the component owns its state.
disabled- Type
booleanDefaultfalseWhether interaction is unavailable.
disabledItems- Type
readonly string[]Default[]Item values excluded from focus and selection.
form- Type
stringDefaultundefinedID of the native form associated with the control.
items- Type
readonly string[]DefaultRequiredOrdered item values managed by the component.
modelValue- Type
stringDefaultundefinedCurrent value when state is controlled by the parent.
name- Type
stringDefaultundefinedName used for native form submission.
readonly- Type
booleanDefaultfalseWhether the value can be inspected but not changed.
required- Type
booleanDefaultfalseWhether the control must contain a valid value before submission.
RatingClearProps
as- Type
PrimitiveAsDefault'button'Element or component rendered for this part.
asChild- Type
booleanDefaultfalseWhether to merge this part into its single child instead of rendering a wrapper.
Slots
RatingRootSlotProps
clearable- Type
booleanWhether the current value can be cleared.
disabled- Type
booleanWhether interaction is unavailable.
highlightedValue- Type
string | nullValue currently highlighted for interaction.
readonly- Type
booleanWhether the value can be inspected but not changed.
value- Type
stringCurrent value exposed by this contract.
Events
RatingRoot
update:modelValue- Payload
stringEmitted when the component requests a new controlled value.
Other types
RatingValueChangeHandler
type RatingValueChangeHandler = (value: string) => voidParts
Shared scope: [data-scope="rating"]. Combine it with a part selector to keep styles local to this component.
| Part | Selector | Role | Extra attributes |
|---|---|---|---|
root | [data-part="root"] | Defines the component boundary and owns its composed parts. | — |
item | [data-part="item"] | Represents one selectable or actionable item. | — |
indicator | [data-part="indicator"] | Shows state or position without replacing the primary content. | — |
clear | [data-part="clear"] | Clears the current value or collection. | — |
Keyboard interaction
| Key | Behavior |
|---|---|
| Arrow keys | Move the active option in the visible orientation. |
| Home / End | Move to the first or last eligible option. |
| Enter / Space | Select or activate the current option. |
| Printable text | Move to the next matching option when typeahead is available. |
Accessibility
Rating choices use radio-group semantics, keep every score named, and provide an explicit clear action.
See the corresponding WAI-ARIA pattern for the host accessibility contract.
