Rank
Select options by rank: click (or press Enter) to add an option to the ranking sequence; selected options show a rank badge. Move up, move down, and remove are visible buttons — no drag required. The value is an ordered key array, so a partial ranking is simply an ordered subset.
Basic usage
Click an option to add it; click a ranked item (or its remove button) to take it out.
Preference ranking
Reordering and minimum ranks
min-ranks sets the minimum number of ranked items; the count is shown live. Clicking "Submit" calls validate(): falling short shows an error and dispatches oas-invalid, and further selection re-checks silently.
min-ranks=2
Survey scenario (ranking question)
Ranking questions are common in surveys: respondents order options by preference and the ordered array is submitted. This demo prints the result directly.
Rank the factors you value most
Disabled and readonly
Option-level disabled cannot be added; group-level disabled blocks everything; readonly keeps the normal appearance and ranking but ignores interaction.
disabled / readonly
Inside oas-form (generic form scenario)
A ranking question is registered in the oas-form collection chain (the value channel; the form value is a JSON array of keys), so a named ranking question submits with the form and participates in initial-values / reset. The example below validates it first and then merges its value into the submitted data.
Ranking inside a form
Keyboard and accessibility
- Options and the move-up / move-down / remove controls are native
buttonelements: Tab reachable, activated with Enter / Space; action labels include the option name so same-named buttons stay distinguishable - Rank changes are announced through
aria-live="polite"(for example "Apple is ranked #1"), independent of the visual badge - Rank badges and spacing use logical properties, so RTL mirrors automatically
API
oas-rank
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
disabled | Disable all interaction | boolean | — |
label | Question text (rendered as a caption and used as the group accessible name) | string | — |
min-ranks | Minimum number of ranked items (positive integer); validate() fails below it | string | — |
options | Sortable options as a JSON array [{ key, label?, disabled?, description? }]; string items collapse to key=label | RankOption[] | string | — |
readonly | Readonly: keeps the appearance and ranking but ignores interaction | boolean | — |
value | Rank-ordered key array (JSON); a partial ranking is simply an ordered subset | string[] | string | — |
Property (JS property; see each row for attribute reflection)
| Property | Description | Type | Default |
|---|---|---|---|
options | Sortable option list: get+set channel (array or JSON string); assignment applies immediately without events | RankOption[] | string | — |
value | Current value (ordered key array): get+set channel (array or JSON string); assignment applies immediately without events | string[] | string | — |
Methods
| Method | Signature | Description |
|---|---|---|
validate | validate(): boolean | Validate the minimum rank count and sync the visible error; returns whether it passed (dispatches oas-invalid on failure) |
clear | clear(): void | Clear the ranking (dispatches oas-change) |
Events
| Event | Description |
|---|---|
oas-change | Dispatched on add / remove / move up / move down / clear, detail: { value, key, rank, action } |
oas-invalid | Dispatched when validate() is below min-ranks, detail: { reason, min, count, value } |
CSS Variables
| CSS Variable | Description | Default |
|---|---|---|
--oas-rank-badge-size | Rank badge diameter (default --oas-control-height-sm) | var(--oas-control-height-sm) |