import * as React from "react"; import Code from "../Code"; export default function Priority() { return (

Priority

You've successfully registered hundreds of actions and realize you want to control the order in which they appear.

By default, each action has a base priority value of 0 (Priority.NORMAL). This means each action will be rendered in the order in which it was defined.

Command score

kbar uses command-score under the hood to filter actions based on the current search query. Each action will be given a score and we take the score and simply order by the highest to lowest value.

For finer control, kbar enables you to pass a priority{" "} property as part of an action definition. priority is any number value which is then combined with the command score to determine the final sort order.

You can use priority when defining an action's{" "} section property using the same interface.

{}, section: "Recents" priority: Priority.LOW }) const loginAction = createAction({ name: "Login", perform: () => {}, priority: Priority.HIGH }) const themeAction = createAction({ name: "Dark mode", perform: () => {}, section: { name: "Settings", priority: Priority.HIGH } }) useRegisterActions([ signupAction, loginAction, themeAction ]) `} />

Using the above code as a reference, without any usage of{" "} priority, the order in which the actions will appear will be the order in which they were called:

  1. Signup
  2. Login
  3. Dark mode
However, with the priorities in place, the order will be:
  1. Dark mode
  2. Login
  3. Signup

Groups are sorted first and actions within groups are sorted after.

); }