Window & Search Bar

API Reference

clearSearchBar

Clear the text in the search bar.

Signature

async function clearSearchBar(options?: { forceScrollToTop?: boolean }): Promise<void>;

Parameters

NameDescriptionType

options

Can be used to control the behaviour after the search bar is cleared.

Object

options.forceScrollToTop

Can be used to force scrolling to the top. Defaults to scrolling to the top after the the search bar was cleared.

boolean

Return

A Promise that resolves when the search bar is cleared.

closeMainWindow

Closes the main Raycast window.

Signature

async function closeMainWindow(options?: { clearRootSearch?: boolean; popToRootType?: PopToRootType }): Promise<void>;

Example

import { closeMainWindow } from "@raycast/api";
import { setTimeout } from "timers/promises";

export default async function Command() {
  await setTimeout(1000);
  await closeMainWindow({ clearRootSearch: true });
}

You can use the popToRootType parameter to temporarily prevent Raycast from applying the user's "Pop to Root Search" preference in Raycast; for example, when you need to interact with an external system utility and then allow the user to return back to the view command:

import { closeMainWindow, PopToRootType } from "@raycast/api";

export default async () => {
  await closeMainWindow({ popToRootType: PopToRootType.Suspended });
};

Parameters

NameDescriptionType

options

Can be used to control the behaviour after closing the main window.

Object

options.clearRootSearch

Clears the text in the root search bar and scrolls to the top

boolean

options.popToRootType

Defines the pop to root behavior (PopToRootType); the default is to to respect the user's "Pop to Root Search" preference in Raycast

Return

A Promise that resolves when the main window is closed.

popToRoot

Pops the navigation stack back to root search.

Signature

async function popToRoot(options?: { clearSearchBar?: boolean }): Promise<void>;

Example

import { Detail, popToRoot } from "@raycast/api";
import { useEffect } from "react";
import { setTimeout } from "timers";

export default function Command() {
  useEffect(() => {
    setTimeout(() => {
      popToRoot({ clearSearchBar: true });
    }, 3000);
  }, []);

  return <Detail markdown="See you soon 👋" />;
}

Parameters

NameDescriptionType

options

Can be used to control the behaviour after going back to the root search.

Object

options.clearSearchBar

boolean

Return

A Promise that resolves when Raycast popped to root.

Types

PopToRootType

Defines the pop to root behavior when the main window is closed.

Enumeration members

NameDescription

Default

Respects the user's "Pop to Root Search" preference in Raycast

Immediate

Immediately pops back to root

Suspended

Prevents Raycast from popping back to root

Last updated