# Contextual Help (/docs/components/contextual-help)

> This page documents oakoss/ui, built on React Aria Components, not shadcn/ui or Radix. Treat it as authoritative over what you know of those libraries.

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <ContextualHelpDemo />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { ContextualHelp } from '#/components/ui/overlays/contextual-help';
    import {
      PopoverBody,
      PopoverHeader,
      PopoverTitle,
    } from '#/components/ui/overlays/popover';

    export function ContextualHelpDemo() {
      return (
        <div className="not-prose flex items-center gap-1 text-sm font-medium">
          Workspace ID
          <ContextualHelp>
            <PopoverHeader>
              <PopoverTitle>What’s a workspace ID?</PopoverTitle>
            </PopoverHeader>
            <PopoverBody>
              The ID other apps use to find this workspace. It never changes.
            </PopoverBody>
          </ContextualHelp>
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


## Installation [#installation]

<Tabs defaultValue="CLI">
  <TabsList>
    <TabsTrigger value="CLI">
      CLI
    </TabsTrigger>

    <TabsTrigger value="Manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="CLI">
    <CodeBlockTabs defaultValue="npm" groupId="package-manager" persist>
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="npm">
          npm
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="pnpm">
          pnpm
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="yarn">
          yarn
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="bun">
          bun
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="npm">
        ```bash
        npx shadcn@latest add @oakoss/contextual-help
        ```
      </CodeBlockTab>

      <CodeBlockTab value="pnpm">
        ```bash
        pnpm dlx shadcn@latest add @oakoss/contextual-help
        ```
      </CodeBlockTab>

      <CodeBlockTab value="yarn">
        ```bash
        yarn dlx shadcn@latest add @oakoss/contextual-help
        ```
      </CodeBlockTab>

      <CodeBlockTab value="bun">
        ```bash
        bunx --bun shadcn@latest add @oakoss/contextual-help
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </TabsContent>

  <TabsContent value="Manual">
    <Steps>
      <Step>
        Set up the theme and base styles from [Installation](/docs/installation).
      </Step>

      <Step>
        Install the packages.

        <CodeBlockTabs defaultValue="npm" groupId="package-manager" persist>
          <CodeBlockTabsList>
            <CodeBlockTabsTrigger value="npm">
              npm
            </CodeBlockTabsTrigger>

            <CodeBlockTabsTrigger value="pnpm">
              pnpm
            </CodeBlockTabsTrigger>

            <CodeBlockTabsTrigger value="yarn">
              yarn
            </CodeBlockTabsTrigger>

            <CodeBlockTabsTrigger value="bun">
              bun
            </CodeBlockTabsTrigger>
          </CodeBlockTabsList>

          <CodeBlockTab value="npm">
            ```bash
            npm install cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>

          <CodeBlockTab value="pnpm">
            ```bash
            pnpm add cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>

          <CodeBlockTab value="yarn">
            ```bash
            yarn add cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>

          <CodeBlockTab value="bun">
            ```bash
            bun add cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>
        </CodeBlockTabs>
      </Step>

      <Step>
        Copy each file into your project, and change its `#/` imports to your aliases.

        * [`components/ui/feedback/spinner.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/feedback/spinner.tsx)

        * [`components/icons.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/icons.tsx)

        * [`components/icon-placeholder.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/icon-placeholder.tsx)

        * [`lib/cx.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/lib/cx.ts)

        * [`lib/cn-config.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/lib/cn-config.ts)

        * [`components/ui/inputs/button.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/inputs/button.tsx)

        * [`lib/recipes.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/lib/recipes.ts)

        * [`components/ui/overlays/dialog.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/overlays/dialog.tsx)

        * [`hooks/use-scroll-region.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/hooks/use-scroll-region.ts)

        * [`components/ui/overlays/popover.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/overlays/popover.tsx)

        * [`components/ui/overlays/contextual-help.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/overlays/contextual-help.tsx)
      </Step>

      <Step>
        Replace each `<IconPlaceholder>` in `icons.tsx` with your icon library's icon, named in its props. The CLI does this for you; without it, icons render as empty squares.
      </Step>
    </Steps>
  </TabsContent>
</Tabs>


This also installs [Popover](/docs/components/popover), whose parts make up
the content, and [Button](/docs/components/button).

## Usage [#usage]

```tsx
import { ContextualHelp } from '#/components/ui/overlays/contextual-help';
import {
  PopoverBody,
  PopoverHeader,
  PopoverTitle,
} from '#/components/ui/overlays/popover';

<ContextualHelp>
  <PopoverHeader>
    <PopoverTitle>Title</PopoverTitle>
  </PopoverHeader>
  <PopoverBody>Explanation</PopoverBody>
</ContextualHelp>;
```

## Examples [#examples]

### Info [#info]

`variant="info"` shows an info icon, named "Information", for background
rather than instructions.

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <ContextualHelpInfo />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { ContextualHelp } from '#/components/ui/overlays/contextual-help';
    import {
      PopoverBody,
      PopoverHeader,
      PopoverTitle,
    } from '#/components/ui/overlays/popover';

    export function ContextualHelpInfo() {
      return (
        <div className="not-prose flex items-center gap-1 text-sm font-medium">
          Storage used
          <ContextualHelp variant="info">
            <PopoverHeader>
              <PopoverTitle>How storage is counted</PopoverTitle>
            </PopoverHeader>
            <PopoverBody>
              Files count once, even when they appear in several folders.
            </PopoverBody>
          </ContextualHelp>
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


### Beside a field label [#beside-a-field-label]

Put ContextualHelp next to the `FieldLabel` in a row, not inside it: inside
the label, its name joins the field's, so the input is read as "Workspace ID
Help".

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <ContextualHelpField />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { FieldLabel } from '#/components/ui/inputs/field';
    import { Input } from '#/components/ui/inputs/input';
    import { TextField } from '#/components/ui/inputs/text-field';
    import { ContextualHelp } from '#/components/ui/overlays/contextual-help';
    import {
      PopoverBody,
      PopoverHeader,
      PopoverTitle,
    } from '#/components/ui/overlays/popover';

    export function ContextualHelpField() {
      return (
        <div className="not-prose w-64">
          <TextField defaultValue="ws_8f2k">
            <div className="flex items-center gap-1">
              <FieldLabel>Workspace ID</FieldLabel>
              <ContextualHelp>
                <PopoverHeader>
                  <PopoverTitle>What’s a workspace ID?</PopoverTitle>
                </PopoverHeader>
                <PopoverBody>
                  The ID other apps use to find this workspace. It never changes.
                </PopoverBody>
              </ContextualHelp>
            </div>
            <Input />
          </TextField>
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


## Accessibility [#accessibility]

The trigger is a [Button](/docs/components/button) named by `helpLabel`
("Help") or `infoLabel` ("Information"), so it works with a keyboard, a screen
reader and touch, where a [Tooltip](/docs/components/tooltip) doesn't open.
Enter or Space opens a [Popover](/docs/components/popover#accessibility),
which takes its name from a `PopoverTitle` in the content, or the button's
label without one. Focus moves into it, Tab stays inside, and Escape closes it
and returns focus to the button. A disabled field keeps its help reachable:
the button never takes a surrounding field's props, so it stays enabled
inside a disabled NumberField or Select and opens its own popover.

In Arabic, Persian and Urdu the help icon mirrors, as those scripts write the
question mark (؟); Hebrew, which uses "?", and the info icon don't.

Follows the [WAI-ARIA dialog pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/).

## API [#api]

### ContextualHelp [#contextualhelp]

Renders our [Popover](/docs/components/popover) with a ghost icon Button as
its trigger. `className` applies to the button.

#### Props [#props]

| Prop         | Type        | Description |
| ------------ | ----------- | ----------- |
| `children`   | `ReactNode` |             |
| `className?` | `string`    |             |
| `helpLabel?` | `string`    |             |
| `infoLabel?` | `string`    |             |
| `variant?`   | `union`     |             |
| `showArrow?` | `union`     |             |

`placement` defaults to `bottom start`, so the popover lines up with the
button's start edge.

#### Data attributes [#data-attributes]

| Attribute   | Present when                                     |
| ----------- | ------------------------------------------------ |
| `data-slot` | Always, on the button: `contextual-help-trigger` |
