Skip to content

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

Nothing ranked yet

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

Submit

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

Submit survey

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

Submit form

Keyboard and accessibility ​

  • Options and the move-up / move-down / remove controls are native button elements: 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 ​

AttributeDescriptionTypeDefault
disabledDisable all interactionboolean—
labelQuestion text (rendered as a caption and used as the group accessible name)string—
min-ranksMinimum number of ranked items (positive integer); validate() fails below itstring—
optionsSortable options as a JSON array [{ key, label?, disabled?, description? }]; string items collapse to key=labelRankOption[] | string—
readonlyReadonly: keeps the appearance and ranking but ignores interactionboolean—
valueRank-ordered key array (JSON); a partial ranking is simply an ordered subsetstring[] | string—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
optionsSortable option list: get+set channel (array or JSON string); assignment applies immediately without eventsRankOption[] | string—
valueCurrent value (ordered key array): get+set channel (array or JSON string); assignment applies immediately without eventsstring[] | string—

Methods ​

MethodSignatureDescription
validatevalidate(): booleanValidate the minimum rank count and sync the visible error; returns whether it passed (dispatches oas-invalid on failure)
clearclear(): voidClear the ranking (dispatches oas-change)

Events ​

EventDescription
oas-changeDispatched on add / remove / move up / move down / clear, detail: { value, key, rank, action }
oas-invalidDispatched when validate() is below min-ranks, detail: { reason, min, count, value }

CSS Variables ​

CSS VariableDescriptionDefault
--oas-rank-badge-sizeRank badge diameter (default --oas-control-height-sm)var(--oas-control-height-sm)

Released under the MIT OR Apache-2.0 License.