← All Components
<mth-rating>
Form-associated star rating control implementing radiogroup and roving focus with hover preview, optional half-stars, and keyboard selection.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-rating>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/rating"></script>
<mth-rating max="5" size="sm"></mth-rating>import '@methane-ui/ui/rating';
import '@methane-ui/react';
export function Example() {
return <mth-rating max="5" size="sm"></mth-rating>;
}<script setup lang="ts">
import '@methane-ui/ui/rating';
</script>
<template>
<mth-rating max="5" size="sm"></mth-rating>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/rating';
import { MthRatingDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthRatingDirective],
template: `<mth-rating max="5" size="sm"></mth-rating>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/rating';
import MthRating from '@methane-ui/svelte/MthRating.svelte';
</script>
<MthRating max="5" size="sm"></MthRating>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
name | name | string | "" | Form field name. |
value | value | string | "" | Current selected rating string (e.g. "4" or "3.5"). |
defaultValue | default-value | string | "" | Initial rating string used on reset. |
max | max | number | 5 | Maximum star count. |
label | label | string | "" | Group label text. |
hint | hint | string | "" | Helper message. |
error | error | string | "" | Error message. |
size | size | 'sm' | 'md' | 'lg' | "md" | Star icon size. |
precision | precision | number | 1 | Selection increment (1 or 0.5). |
clearable | clearable | boolean | false | Whether clicking the active star clears the value. |
disabled | disabled | boolean | false | Disables all star buttons. |
readonly | readonly | boolean | false | Prevents rating changes. |
required | required | boolean | false | Marks rating required for form validation. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-change | { value: string; rating: number } | Dispatched when the user selects or clears a rating. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| ArrowRight | ltr | star focused | moves focus to next star |
| ArrowLeft | rtl | star focused | moves focus to next star in RTL |
| Home / End | both | star focused | moves focus to first or last star |
| Enter / Space | both | star focused | selects focused star rating |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 4 APG keyboard transitions across LTR/RTL. | mth-rating.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(dirty), :state(touched), :state(user-invalid), :state(disabled), :state(required). | Conformance suite |
| i18n | Routes 4 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |