Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-rating>

@methane-ui/ui~9.0 KB brotli (cold + Lit)~2.6 KB marginal

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

Interactive StageLive Custom Element · <mth-rating> (@methane-ui/ui)
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>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
namenamestring""Form field name.
valuevaluestring""Current selected rating string (e.g. "4" or "3.5").
defaultValuedefault-valuestring""Initial rating string used on reset.
maxmaxnumber5Maximum star count.
labellabelstring""Group label text.
hinthintstring""Helper message.
errorerrorstring""Error message.
sizesize'sm' | 'md' | 'lg'"md"Star icon size.
precisionprecisionnumber1Selection increment (1 or 0.5).
clearableclearablebooleanfalseWhether clicking the active star clears the value.
disableddisabledbooleanfalseDisables all star buttons.
readonlyreadonlybooleanfalsePrevents rating changes.
requiredrequiredbooleanfalseMarks rating required for form validation.

Events

EventDetail TypeDescription
mth-change{ value: string; rating: number }Dispatched when the user selects or clears a rating.

APG Keyboard Matrix

KeyDirectionWhenExpected Behavior
ArrowRightltrstar focusedmoves focus to next star
ArrowLeftrtlstar focusedmoves focus to next star in RTL
Home / Endbothstar focusedmoves focus to first or last star
Enter / Spacebothstar focusedselects focused star rating

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusdelegatesFocus: true with zero host internals.role (ADR-014).lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
keyboardImplements all 4 APG keyboard transitions across LTR/RTL.mth-rating.spec.test.ts
statesExposes ElementInternals CustomStateSet flags: :state(dirty), :state(touched), :state(user-invalid), :state(disabled), :state(required).Conformance suite
i18nRoutes 4 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test