# Creating Custom Context Menu Items

Canonical page: https://www.adaptabletools.com/docs/ui-context-menu-custom-items

- Bespoke Menu Items can be added to the Context Menu by developers

## Topics on this Page

| Approach                                           | When to use                                                                                                                                              |
| -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Standard custom item](#standard-custom-menu-item) | `menuType: 'User'` with `label`, `onClick`, optional `subMenuItems` — combine inside `customContextMenu`                                                 |
| [Framework menu row](#react-custom-menu-component) | `frameworkComponent` / `render` for richer UI — see also [Building Custom Components](https://www.adaptabletools.com/docs/ui-tutorial-building-custom-components/index.md) |

Return the full menu array from **`customContextMenu`** in [Context Menu Options](https://www.adaptabletools.com/docs/technical-reference-context-menu/index.md). Configure layout first on [Configuring the Context Menu](https://www.adaptabletools.com/docs/ui-context-menu-configuring/index.md).

Developers can provide **bespoke** menu items in the Context Menu.

This is done using the `customContextMenu` callback in [Context Menu Options](https://www.adaptabletools.com/docs/technical-reference-context-menu/index.md).

Each item is a [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md) with properties such as `label`, `icon`, `hidden`, `disabled`, `onClick`, and `subMenuItems`.

### Anatomy of a Custom Context Menu Item

The key object is [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md):

| Property | Type | Description |
| --- | --- | --- |
| [disabled](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#disabled) | `boolean` | Whether menu item is disabled |
| [frameworkComponent](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#frameworkcomponent) | [`MenuItemFrameworkComponent`](https://www.adaptabletools.com/docs/reference/menuitemframeworkcomponent.md)`<`[`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md)`>` | Optional Framework Component (React, Angular or Vue) used to render the<br/>content of this menu item.<br/><br/>When supplied, AG Grid renders the component inside the menu row using<br/>its own framework adapter. The component receives AG Grid&#39;s<br/>`CustomMenuItemProps`, with the AdapTable-specific extras<br/>(`adaptableApi`, `menuContext`, plus anything passed via<br/>`menuItemParams`) available as `props.menuItemParams`.<br/><br/>Supported in the React, Vue and Angular variants of AdapTable.<br/><br/>For Vue, supply a factory that returns the Vue Component (NOT a render<br/>call), e.g. `({ adaptableApi }) => MyMenuItem`. AG Grid Vue then<br/>instantiates the component using its own framework adapter and passes<br/>`name`, `icon`, `menuItemParams`, ... as props.<br/><br/>For Angular, supply `{ type: MyMenuItemComponent }` where the component<br/>implements `IMenuItemAngularComp` (with `agInit(params)` to receive<br/>`params.menuItemParams.adaptableApi` and `params.menuItemParams.menuContext`).<br/>The `onSetup` callback on `AngularFrameworkComponent` is NOT honoured<br/>for menu items because AG Grid owns the component lifecycle. |
| [hidden](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#hidden) | `boolean` | Whether menu item is hidden |
| [icon](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#icon) | [`AdaptableIcon`](https://www.adaptabletools.com/docs/reference/adaptableicon.md) | Optional icon to display |
| [label](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#label) | `string` | Text to appear in the Menu Item |
| [menuItemParams](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#menuitemparams) | `Record<string, unknown>` | Extra parameters passed through to the Framework Component (alongside<br/>`adaptableApi` and `menuContext`). |
| [menuType](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#menutype) | `'User'` | Type of Menu - always &#39;User&#39; |
| [onClick](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#onclick) | `(menuContext: `[`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md)`) => void` | Function invoked when the Menu Item is clicked |
| [subMenuItems](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md#submenuitems) | [`CustomContextMenuItem`](https://www.adaptabletools.com/docs/reference/customcontextmenuitem.md)`[]` | Array of Menu Items, enabling limitless levels of menus |

The `onClick` handler receives [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [adaptableColumn](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#adaptablecolumn) | [`AdaptableColumn`](https://www.adaptabletools.com/docs/reference/adaptablecolumn.md)`<TData>` | Current AdapTable Column |
| [agGridColumn](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#aggridcolumn) | `Column` | Current AG Grid Column |
| [gridCell](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#gridcell) | [`GridCell`](https://www.adaptabletools.com/docs/reference/gridcell.md)`<TData>` | Cell that has been clicked; contains cell value |
| [isGroupedNode](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#isgroupednode) | `boolean` | Whether current AG Grid row node is grouped |
| [isRowGroupColumn](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#isrowgroupcolumn) | `boolean` | Whether current Column is Row Grouped |
| [isSelectedCell](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#isselectedcell) | `boolean` | Whether cell that was clicked is also currently selected |
| [isSelectedRow](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#isselectedrow) | `boolean` | Whether cell that was clicked is in a Row that is currently selected |
| [isSingleSelectedCell](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#issingleselectedcell) | `boolean` | Whether the clicked cell is the only selected cell |
| [isSingleSelectedColumn](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#issingleselectedcolumn) | `boolean` | Whether Column that was clicked is only column with selected cells |
| [primaryKeyValue](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#primarykeyvalue) | `any` | Value of Primary Key column in current row |
| [rowNode](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#rownode) | `IRowNode<TData>` | Current AG Grid row node |
| [selectedCellInfo](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#selectedcellinfo) | [`SelectedCellInfo`](https://www.adaptabletools.com/docs/reference/selectedcellinfo.md)`<TData>` | Currently selected cells in the grid |
| [selectedRowInfo](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#selectedrowinfo) | [`SelectedRowInfo`](https://www.adaptabletools.com/docs/reference/selectedrowinfo.md)`<TData>` | Currently selected rows in the grid |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/contextmenucontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<!-- framework: vanilla -->
### Vanilla

### Providing a Standard Custom Context Menu Item

A few steps are required to define a standard Context Menu item (no `frameworkComponent`):

The `menuType` is always `'User'`.

The `label` property provides the menu item text. It can be a string or a function that receives [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md) and returns a string.

```ts {3,4}
menuType: 'User',
label: (menuContext: ContextMenuContext) => {
  return menuContext.adaptableApi.dashboardApi.isDashboardCollapsed()
    ? 'Expand Dashboard'
    : 'Collapse Dashboard';
},
```

The `onClick` function runs when the user selects the item. It receives [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md) and returns void.

```ts {2}
onClick: (menuContext: ContextMenuContext) => {
  menuContext.adaptableApi.dashboardApi.isDashboardCollapsed()
    ? menuContext.adaptableApi.dashboardApi.expandDashboard()
    : menuContext.adaptableApi.dashboardApi.collapseDashboard();
},
```

Use `hidden` and `disabled` to control visibility and whether the item can be selected.

```ts {2,4}
hidden: menuContext.isRowGroupColumn,
disabled: menuContext.adaptableColumn?.dataType == 'date',
```

Supply an [`AdaptableIcon`](https://www.adaptabletools.com/docs/reference/adaptableicon.md) on the `icon` property.

```ts {2}
icon: {
  name: 'theme',
},
```

See [Guide to Adaptable Icons](https://www.adaptabletools.com/docs/ui-tutorial-creating-icon/index.md) for full details on icons

Each menu item can include `subMenuItems` for nested menus. Each sub-item is another [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md).

When the Dashboard is visible, use a **Dashboard** parent with Hide and Float sub items. When it is hidden (`dashboardApi.isDashboardHidden()`), the demo uses a single **Show Dashboard** item that calls `showDashboard()`.

```ts {2}
subMenuItems: [
  {
    menuType: 'User',
    label: 'Hide Dashboard',
    onClick: (menuContext: ContextMenuContext) => {
      menuContext.adaptableApi.dashboardApi.hideDashboard();
    },
  },
  {
    menuType: 'User',
    label: 'Float Dashboard',
    onClick: (menuContext: ContextMenuContext) => {
      menuContext.adaptableApi.dashboardApi.floatDashboard();
    },
  },
],
```

The `customContextMenu` callback receives AG Grid and AdapTable menu structures on `context`. Build items such as `changeThemeMenuItem` and `dashboardMenuItem`, then place them where you want in the Context Menu (often before the default blocks).

```ts {5}
contextMenuOptions: {
  customContextMenu: (context: CustomContextMenuContext) => {
    return [
      changeThemeMenuItem,
      dashboardMenuItem,
      '-',
      ...context.defaultAgGridMenuStructure,
      '-',
      ...context.defaultAdaptableMenuStructure,
    ];
  },
},
```

**Example: Context Menu: Custom Menu Items**

Adding Custom Menu Items to Context Menus

- **Show Dark Theme** / **Show Light Theme** — single action at the top of the Context Menu; hidden on row-group columns; disabled for `date` columns
- **Dashboard** — **Show Dashboard** when the Dashboard is hidden; otherwise a sub menu with Hide and Float
- Default AG Grid and AdapTable menu items remain below

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  CustomContextMenuContext,
  UserContextMenuItem,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Context Menu Items',
  contextMenuOptions: {
    customContextMenu: (context: CustomContextMenuContext) => {
      const {
        defaultAgGridMenuStructure,
        defaultAdaptableMenuStructure,
        isRowGroupColumn,
        adaptableColumn,
        adaptableApi,
      } = context;

      const changeThemeMenuItem: UserContextMenuItem = {
        menuType: 'User',
        label:
          adaptableApi.themeApi.getCurrentTheme() == 'light'
            ? 'Show Dark Theme'
            : 'Show Light Theme',
        icon: {
          name: 'theme',
        },
        hidden: isRowGroupColumn,
        disabled: adaptableColumn?.dataType == 'date',
        onClick: () =>
          adaptableApi.themeApi.getCurrentTheme() == 'light'
            ? adaptableApi.themeApi.loadDarkTheme()
            : adaptableApi.themeApi.loadLightTheme(),
      };

      const dashboardMenuItem: UserContextMenuItem =
        adaptableApi.dashboardApi.isDashboardHidden()
          ? {
              menuType: 'User',
              label: 'Show Dashboard',
              onClick: () => adaptableApi.dashboardApi.showDashboard(),
            }
          : {
              menuType: 'User',
              label: 'Dashboard',
              subMenuItems: [
                {
                  menuType: 'User',
                  label: 'Hide Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.hideDashboard(),
                },
                {
                  menuType: 'User',
                  label: 'Float Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.floatDashboard(),
                },
              ],
            };

      return [
        changeThemeMenuItem,
        dashboardMenuItem,
        '-',
        ...defaultAgGridMenuStructure,
        '-',
        ...defaultAdaptableMenuStructure,
      ];
    },
  },
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['SystemStatus'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Grouped Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'open_issues_count',
            'week_issue_change',
            'updated_at',
            'license',
            'created_at',
            'has_wiki',
            'pushed_at',
            'open_issues_count',
            'description',
          ],
          AutoSizeColumns: true,
          Name: 'Grouped Layout',
          RowGroupValues: {
            RowGroupDefaultBehavior: 'collapsed',
            GroupKeys: [
              {
                RowGroupedColumns: ['language'],
                ExceptionGroupKeys: [['JavaScript']],
              },
            ],
          },
          RowGroupedColumns: ['language'],
        },
      ],
    },
  },
};
```

<!-- /framework -->
<!-- framework: react,angular,vue -->
### React / Angular / Vue

There are two ways to add bespoke Context Menu items:

1. **Standard menu item** — a [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md) with `label`, `onClick`, and related properties
2. **Framework menu component** — `frameworkComponent` when you need custom UI inside the menu item

## Standard Custom Menu Item

This option is suitable for most use cases and no `frameworkComponent` is required.

### Providing a Standard Custom Context Menu Item

Most custom entries use a standard [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md).

AdapTable renders the menu item for you.

The `menuType` is always `'User'`.

The `label` is the menu text—a string, or a function that receives [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md) and returns a string.

```ts {1,2}
menuType: 'User',
label: (menuContext: ContextMenuContext) => {
  return menuContext.adaptableApi.themeApi.getCurrentTheme() === 'light'
    ? 'Show Dark Theme'
    : 'Show Light Theme';
},
```

`onClick` runs when the user selects the item. It receives [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md).

```ts {1}
onClick: (menuContext: ContextMenuContext) => {
  const {themeApi} = menuContext.adaptableApi;
  themeApi.getCurrentTheme() === 'light'
    ? themeApi.loadDarkTheme()
    : themeApi.loadLightTheme();
},
```

Use `hidden` and `disabled` on the [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md).

```ts {1,2}
hidden: context.isRowGroupColumn,
disabled: context.adaptableColumn?.dataType === 'date',
```

The icon can be an object, URL, or HTML element.

```ts {2}
icon: {
  name: 'theme',
},
```

See [Guide to Adaptable Icons](https://www.adaptabletools.com/docs/ui-tutorial-creating-icon/index.md) for full details on Icons

Use `subMenuItems` for nested menus. Each entry is another [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md).

When the Dashboard is visible, use a **Dashboard** parent with Hide and Float sub items. When it is hidden (`dashboardApi.isDashboardHidden()`), the demos use a single **Show Dashboard** item that calls `showDashboard()`.

```ts {1}
subMenuItems: [
  {
    menuType: 'User',
    label: 'Hide Dashboard',
    onClick: (menuContext: ContextMenuContext) => {
      menuContext.adaptableApi.dashboardApi.hideDashboard();
    },
  },
  {
    menuType: 'User',
    label: 'Float Dashboard',
    onClick: (menuContext: ContextMenuContext) => {
      menuContext.adaptableApi.dashboardApi.floatDashboard();
    },
  },
],
```

The `customContextMenu` callback receives default menu structures on `context`. Build items such as `changeThemeMenuItem` and `dashboardMenuItem`, then place them where you want in the Context Menu (often before the default blocks).

```ts {5}
contextMenuOptions: {
  customContextMenu: (context: CustomContextMenuContext) => {
    return [
      changeThemeMenuItem,
      dashboardMenuItem,
      '-',
      ...context.defaultAgGridMenuStructure,
      '-',
      ...context.defaultAdaptableMenuStructure,
    ];
  },
},
```

<!-- /framework -->

<!-- framework: react -->
### React

**Example: Context Menu: Standard Custom Items**

Standard custom Context Menu items (React)

- This example contains 2 standard Custom Context Menu Items:
  - **Show Dark Theme** / **Show Light Theme** — single action; hidden on row-group columns; disabled on `date` columns
  - **Dashboard** — **Show Dashboard** when the Dashboard is hidden; otherwise a sub menu with Hide and Float

Demo project (React); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts  [template]
  agGridModules.ts     [template]
  App.tsx
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.tsx            [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#react).

**`src/App.tsx`**

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
  CustomContextMenuContext,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-react-aggrid';

import {GridOptions} from 'ag-grid-enterprise';

import '@adaptabletools/adaptable-react-aggrid/index.css';
import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {WebFramework} from './rowData';

const App: React.FunctionComponent = () => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const [adaptOptions] = useState<AdaptableOptions<WebFramework>>({
    primaryKey: 'id',
    adaptableId: 'Standard Context Menu Items Demo',
    stateOptions: {loadState: () => Promise.resolve({})},
    contextMenuOptions: {
      customContextMenu: (context: CustomContextMenuContext) => {
        const {
          defaultAgGridMenuStructure,
          defaultAdaptableMenuStructure,
          isRowGroupColumn,
          adaptableColumn,
          adaptableApi,
        } = context;

        const changeThemeMenuItem: UserContextMenuItem = {
          menuType: 'User',
          label:
            adaptableApi.themeApi.getCurrentTheme() === 'light'
              ? 'Show Dark Theme'
              : 'Show Light Theme',
          icon: {name: 'theme'},
          hidden: isRowGroupColumn,
          disabled: adaptableColumn?.dataType === 'date',
          onClick: () => {
            const {themeApi} = adaptableApi;
            themeApi.getCurrentTheme() === 'light'
              ? themeApi.loadDarkTheme()
              : themeApi.loadLightTheme();
          },
        };

        const dashboardMenuItem: UserContextMenuItem =
          adaptableApi.dashboardApi.isDashboardHidden()
            ? {
                menuType: 'User',
                label: 'Show Dashboard',
                onClick: () => adaptableApi.dashboardApi.showDashboard(),
              }
            : {
                menuType: 'User',
                label: 'Dashboard',
                subMenuItems: [
                  {
                    menuType: 'User',
                    label: 'Hide Dashboard',
                    onClick: menuContext =>
                      menuContext.adaptableApi.dashboardApi.hideDashboard(),
                  },
                  {
                    menuType: 'User',
                    label: 'Float Dashboard',
                    onClick: menuContext =>
                      menuContext.adaptableApi.dashboardApi.floatDashboard(),
                  },
                ],
              };

        return [
          changeThemeMenuItem,
          dashboardMenuItem,
          '-',
          ...defaultAgGridMenuStructure,
          '-',
          ...defaultAdaptableMenuStructure,
        ];
      },
    },
    initialState: {
      Dashboard: {
        Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
      },
      Theme: {CurrentTheme: 'dark'},
      Layout: {
        CurrentLayout: 'Standard Layout',
        Layouts: [
          {
            Name: 'Standard Layout',
            TableColumns: [
              'name',
              'language',
              'github_stars',
              'license',
              'created_at',
              'has_wiki',
              'updated_at',
              'pushed_at',
              'description',
            ],
            AutoSizeColumns: true,
          },
        ],
      },
    },
  });
  const [agGridOptions] = useState<GridOptions>(gridOptions);

  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
    </div>
  );
};

export default App;
```

## React Custom Menu Component

Use `frameworkComponent` on [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md) when `label`, `icon`, and `onClick` are not enough.

For example if you want a custom layout, extra controls, or live state in the shortcut area.

AG Grid owns the menu lifecycle (open, close, keyboard navigation).

- AdapTable forwards your component to AG Grid's <a href="https://www.ag-grid.com/react-data-grid/component-menu-item/" target="_blank" rel="noreferrer">Menu Item Component</a> integration
- Use `props.menuItemParams` for [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md) and [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md)

### Providing a Custom React Context Menu Item

This component receives AG Grid props plus `menuItemParams` populated by AdapTable with `adaptableApi` and the active `menuContext`.

Call `useGridMenuItem({ configureDefaults: () => true })` to opt into AG Grid's default menu behaviour.

```tsx
import {useGridMenuItem} from 'ag-grid-react';
import {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-react-aggrid';

type MenuItemProps = {
  name: string;
  menuItemParams: {
    adaptableApi: AdaptableApi;
    menuContext: ColumnMenuContext | ContextMenuContext;
  };
};

export const ThemeToggleMenuItem = (props: MenuItemProps) => {
  useGridMenuItem({configureDefaults: () => true});

  const {adaptableApi} = props.menuItemParams;
  const isDark = adaptableApi.themeApi.getCurrentTheme() === 'dark';

  return (
    <div>
      <span
        className="ag-menu-option-part ag-menu-option-icon"
        role="presentation"
      />
      <span className="ag-menu-option-part ag-menu-option-text">
        {props.name}
      </span>
      <span className="ag-menu-option-part ag-menu-option-shortcut">
        Currently: {isDark ? 'Dark' : 'Light'}
      </span>
      <span className="ag-menu-option-part ag-menu-option-popup-pointer" />
    </div>
  );
};
```

In `customContextMenu`, return a `UserContextMenuItem` and assign your React component to `frameworkComponent`.

```ts {6}
contextMenuOptions: {
  customContextMenu: (context: CustomContextMenuContext) => {
    const themeMenuItem: UserContextMenuItem = {
      menuType: 'User',
      label: 'Toggle Theme',
      frameworkComponent: ThemeToggleMenuItem,
      onClick: () => {
        const themeApi = context.adaptableApi.themeApi;
        themeApi.getCurrentTheme() === 'dark'
          ? themeApi.loadLightTheme()
          : themeApi.loadDarkTheme();
      },
    };
    return [
      themeMenuItem,
      '-',
      ...context.defaultAdaptableMenuStructure,
    ];
  },
},
```

`adaptableApi` and `menuContext` are on `props.menuItemParams`.

```ts
const {adaptableApi, menuContext} = props.menuItemParams;
const columnId = menuContext.adaptableColumn?.columnId;
```

### Anatomy of a React Context Menu Item Component

AG Grid passes `name`, `icon`, `disabled`, `subMenu`, `shortcut`, and `checked` to your component.

AdapTable adds on `props.menuItemParams`:

- `adaptableApi` — [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md)
- `menuContext` — [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md) or [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md)

Use `useGridMenuItem({ configureDefaults: () => true })` for default click, keyboard, and dismiss behaviour.

Wrap the four `ag-menu-option-part` spans in a single root element (for example a `<div>`). Do not use a React Fragment: AG Grid treats only the first child of the React container as the menu row, so a fragment leaves the label and shortcut unstyled and invisible.

**Example: Context Menu: Framework Menu Row (React)**

Providing a React Component as a Custom Context Menu Item

- Theme-toggle menu item at the top of every Context Menu

Demo project (React); the files without a marker are shown below:

```text
src/
  agGridModules.ts         [template]
  App.tsx
  columnDefs.ts            [template]
  gridOptions.ts           [template]
  index.tsx                [template]
  onAdaptableReady.ts      [template]
  rowData.ts               [template]
  styles.css               [template]
  ThemeToggleMenuItem.tsx
package.json               [template]
tsconfig.json              [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#react).

**`src/App.tsx`**

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
  CustomColumnMenuContext,
  CustomContextMenuContext,
  UserColumnMenuItem,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-react-aggrid';

import {GridOptions} from 'ag-grid-enterprise';

// import adaptable css
import '@adaptabletools/adaptable-react-aggrid/index.css';
import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {ThemeToggleMenuItem} from './ThemeToggleMenuItem';
import {WebFramework} from './rowData';

const App: React.FunctionComponent = () => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const [adaptOptions] = useState<AdaptableOptions<WebFramework>>({
    primaryKey: 'id',
    adaptableId: 'Custom Menu Item Demo',
    stateOptions: {loadState: () => Promise.resolve({})},
    contextMenuOptions: {
      customContextMenu: (context: CustomContextMenuContext) => {
        const themeMenuItem: UserContextMenuItem = {
          menuType: 'User',
          label: 'Toggle Theme',
          frameworkComponent: ThemeToggleMenuItem,
          onClick: () => {
            const themeApi = context.adaptableApi.themeApi;
            themeApi.getCurrentTheme() === 'dark'
              ? themeApi.loadLightTheme()
              : themeApi.loadDarkTheme();
          },
        };
        return [themeMenuItem, '-', ...context.defaultAdaptableMenuStructure];
      },
    },
    initialState: {
      Theme: {CurrentTheme: 'dark'},
      Layout: {
        CurrentLayout: 'Standard Layout',
        Layouts: [
          {
            Name: 'Standard Layout',
            TableColumns: [
              'name',
              'language',
              'github_stars',
              'license',
              'created_at',
              'has_wiki',
              'updated_at',
              'pushed_at',
              'description',
            ],
            AutoSizeColumns: true,
          },
        ],
      },
    },
  });
  const [agGridOptions] = useState<GridOptions>(gridOptions);

  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <div id="demoOutputAbove"></div>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
      <div id="demoOutputBelow"></div>
    </div>
  );
};
export default App;
```

**`src/ThemeToggleMenuItem.tsx`**

```ts
import * as React from 'react';
import {useGridMenuItem} from 'ag-grid-react';
import {
  AdaptableReactMenuItemProps,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-react-aggrid';

type AnyMenuContext = ColumnMenuContext | ContextMenuContext;

export type ThemeToggleMenuItemProps = AdaptableReactMenuItemProps<AnyMenuContext>;

export const ThemeToggleMenuItem = (props: ThemeToggleMenuItemProps) => {
  // Opt-in to AG Grid's default click / keyboard / hover behaviour so this
  // row dismisses the menu and triggers AdapTable's onClick automatically.
  useGridMenuItem({configureDefaults: () => true});

  const {adaptableApi} = props.menuItemParams;
  const isDark = adaptableApi.themeApi.getCurrentTheme() === 'dark';

  return (
    <div>
      <span
        className="ag-menu-option-part ag-menu-option-icon"
        role="presentation"
      />
      <span className="ag-menu-option-part ag-menu-option-text">
        {props.name}
      </span>
      <span
        className="ag-menu-option-part ag-menu-option-shortcut"
        style={{opacity: 0.7}}>
        {isDark ? 'Dark' : 'Light'}
      </span>
      <span className="ag-menu-option-part ag-menu-option-popup-pointer" />
    </div>
  );
};
```



<!-- /framework -->

<!-- framework: angular -->
### Angular

**Example: Context Menu: Standard Custom Items**

Standard custom Context Menu items (Angular)

- This example contains 2 standard Custom Context Menu Items:
  - **Show Dark Theme** / **Show Light Theme** — single action; hidden on row-group columns; disabled on `date` columns
  - **Dashboard** — **Show Dashboard** when the Dashboard is hidden; otherwise a sub menu with Hide and Float

Demo project (Angular); the files without a marker are shown below:

```text
src/
  app/
    adaptableOptions.ts
    agGridModules.ts     [template]
    app.component.ts     [template]
    app.module.ts        [template]
    columnDefs.ts        [template]
    gridOptions.ts       [template]
    onAdaptableReady.ts  [template]
    rowData.ts           [template]
    styles.css           [template]
  index.html             [template]
  main.ts                [template]
  polyfills.ts           [template]
package.json             [template]
tsconfig.json            [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#angular).

**`src/app/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  CustomContextMenuContext,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-angular-aggrid';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Standard Context Menu Items Demo',
  contextMenuOptions: {
    customContextMenu: (context: CustomContextMenuContext) => {
      const {
        defaultAgGridMenuStructure,
        defaultAdaptableMenuStructure,
        isRowGroupColumn,
        adaptableColumn,
        adaptableApi,
      } = context;

      const changeThemeMenuItem: UserContextMenuItem = {
        menuType: 'User',
        label:
          adaptableApi.themeApi.getCurrentTheme() === 'light'
            ? 'Show Dark Theme'
            : 'Show Light Theme',
        icon: {name: 'theme'},
        hidden: isRowGroupColumn,
        disabled: adaptableColumn?.dataType === 'date',
        onClick: () => {
          const {themeApi} = adaptableApi;
          themeApi.getCurrentTheme() === 'light'
            ? themeApi.loadDarkTheme()
            : themeApi.loadLightTheme();
        },
      };

      const dashboardMenuItem: UserContextMenuItem =
        adaptableApi.dashboardApi.isDashboardHidden()
          ? {
              menuType: 'User',
              label: 'Show Dashboard',
              onClick: () => adaptableApi.dashboardApi.showDashboard(),
            }
          : {
              menuType: 'User',
              label: 'Dashboard',
              subMenuItems: [
                {
                  menuType: 'User',
                  label: 'Hide Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.hideDashboard(),
                },
                {
                  menuType: 'User',
                  label: 'Float Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.floatDashboard(),
                },
              ],
            };

      return [
        changeThemeMenuItem,
        dashboardMenuItem,
        '-',
        ...defaultAgGridMenuStructure,
        '-',
        ...defaultAdaptableMenuStructure,
      ];
    },
  },
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Angular Custom Menu Component

Use `frameworkComponent` on [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md) when `label`, `icon`, and `onClick` are not enough.

For example if you want inline switches, multi-button rows, or inputs.

AG Grid owns the menu lifecycle (open, close, keyboard navigation).

AdapTable forwards your component to AG Grid's <a href="https://www.ag-grid.com/angular-data-grid/component-menu-item/" target="_blank" rel="noreferrer">Menu Item Component</a> integration

In `agInit`, read `params.menuItemParams` for [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md), [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md), and any extra fields you supplied on the menu item.

- The `onSetup` function on `AngularFrameworkComponent` is **not** invoked for menu items
- This is because AG Grid owns the component lifecycle

### Providing a Custom Angular Context Menu Item

This is a standard Angular Component that implements `IMenuItemAngularComp` from `ag-grid-angular`.

It must implement:

- `agInit(params)` — called when the menu opens
- `configureDefaults()` — return `true` to opt into AG Grid's default click / keyboard / hover behaviour

```ts
import {ChangeDetectionStrategy, Component} from '@angular/core';
import type {IMenuItemAngularComp} from 'ag-grid-angular';
import type {IMenuItemParams} from 'ag-grid-enterprise';
import type {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable';

type AdaptableMenuItemParams = {
  adaptableApi: AdaptableApi;
  menuContext: ColumnMenuContext | ContextMenuContext;
};

@Component({
  selector: 'app-theme-toggle-menu-item',
  template: `
    <span
      class="ag-menu-option-part ag-menu-option-icon"
      role="presentation"></span>
    <span class="ag-menu-option-part ag-menu-option-text">{{ name }}</span>
    <span
      class="ag-menu-option-part ag-menu-option-shortcut"
      style="opacity: 0.7;">
      {{ currentTheme === 'dark' ? 'Dark' : 'Light' }}
    </span>
    <span class="ag-menu-option-part ag-menu-option-popup-pointer"></span>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ThemeToggleMenuItemComponent implements IMenuItemAngularComp {
  name = '';
  currentTheme: 'light' | 'dark' = 'light';

  agInit(params: IMenuItemParams): void {
    this.name = params.name ?? '';
    const menuParams = params.menuItemParams as AdaptableMenuItemParams;
    this.currentTheme = menuParams.adaptableApi.themeApi.getCurrentTheme();
  }

  configureDefaults(): boolean {
    return true;
  }
}
```

The menu item component must be declared in your `NgModule`.

```ts {7,12}
import {NgModule} from '@angular/core';
import {AdaptableAngularAgGridModule} from '@adaptabletools/adaptable-angular-aggrid';
import {AgGridModule} from 'ag-grid-angular';
import {BrowserModule} from '@angular/platform-browser';

import {AppComponent} from './app.component';
import {ThemeToggleMenuItemComponent} from './theme-toggle-menu-item.component';

@NgModule({
  declarations: [AppComponent, ThemeToggleMenuItemComponent],
  imports: [BrowserModule, AgGridModule, AdaptableAngularAgGridModule],
  bootstrap: [AppComponent],
})
export class AppModule {}
```

In `customContextMenu`, return a `UserContextMenuItem` and assign your component class via `frameworkComponent.type`.

```ts {6}
contextMenuOptions: {
  customContextMenu: (context) => {
    const themeMenuItem: UserContextMenuItem = {
      menuType: 'User',
      label: 'Toggle Theme',
      frameworkComponent: {type: ThemeToggleMenuItemComponent},
      onClick: () => {
        const themeApi = context.adaptableApi.themeApi;
        themeApi.getCurrentTheme() === 'dark'
          ? themeApi.loadLightTheme()
          : themeApi.loadDarkTheme();
      },
    };
    return [
      themeMenuItem,
      '-',
      ...context.defaultAdaptableMenuStructure,
    ];
  },
},
```

### Anatomy of an Angular Context Menu Item Component

Inside `agInit(params)`, AG Grid exposes fields such as `name`, `icon`, and `disabled`.

AdapTable adds on `params.menuItemParams`:

- `adaptableApi` — [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md)
- `menuContext` — [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md) (or [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md) when the same component is reused on a Column Menu item)
- any extra fields you supplied via `menuItemParams` on the User Menu Item

Return `true` from `configureDefaults()` so AG Grid handles click highlighting, dismissing the menu, and triggering AdapTable's `onClick`.

**Example: Context Menu: Framework Menu Row (Angular)**

Providing an Angular Component as a Custom Context Menu Item

- Theme-toggle menu item at the top of every Context Menu

Demo project (Angular); the files without a marker are shown below:

```text
src/
  app/
    adaptableOptions.ts
    agGridModules.ts                     [template]
    app.component.ts                     [template]
    app.module.ts
    columnDefs.ts                        [template]
    gridOptions.ts                       [template]
    onAdaptableReady.ts                  [template]
    rowData.ts                           [template]
    styles.css                           [template]
    theme-toggle-menu-item.component.ts
  index.html                             [template]
  main.ts                                [template]
  polyfills.ts                           [template]
package.json                             [template]
tsconfig.json                            [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#angular).

**`src/app/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  CustomColumnMenuContext,
  CustomContextMenuContext,
  UserColumnMenuItem,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-angular-aggrid';
import {WebFramework} from './rowData';
import {ThemeToggleMenuItemComponent} from './theme-toggle-menu-item.component';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Menu Item Demo',

  contextMenuOptions: {
    customContextMenu: (context: CustomContextMenuContext) => {
      const themeMenuItem: UserContextMenuItem = {
        menuType: 'User',
        label: 'Toggle Theme',
        frameworkComponent: {type: ThemeToggleMenuItemComponent},
        onClick: () => {
          const themeApi = context.adaptableApi.themeApi;
          themeApi.getCurrentTheme() === 'dark'
            ? themeApi.loadLightTheme()
            : themeApi.loadDarkTheme();
        },
      };
      return [
        themeMenuItem,
        '-',
        ...context.defaultAdaptableMenuStructure,
      ];
    },
  },
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/app/theme-toggle-menu-item.component.ts`**

```ts
import {ChangeDetectionStrategy, Component} from '@angular/core';
import type {IMenuItemAngularComp} from 'ag-grid-angular';
import type {IMenuItemParams} from 'ag-grid-enterprise';
import type {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-angular-aggrid';

type AdaptableMenuItemParams = {
  adaptableApi: AdaptableApi;
  menuContext: ColumnMenuContext | ContextMenuContext;
};

@Component({
  standalone: false,
  selector: 'app-theme-toggle-menu-item',
  template: `
    <span
      class="ag-menu-option-part ag-menu-option-icon"
      role="presentation"></span>
    <span class="ag-menu-option-part ag-menu-option-text">{{ name }}</span>
    <span
      class="ag-menu-option-part ag-menu-option-shortcut"
      style="opacity: 0.7;">
      {{ currentTheme === 'dark' ? 'Dark' : 'Light' }}
    </span>
    <span class="ag-menu-option-part ag-menu-option-popup-pointer"></span>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ThemeToggleMenuItemComponent implements IMenuItemAngularComp {
  name = '';
  currentTheme: 'light' | 'dark' = 'light';

  agInit(params: IMenuItemParams): void {
    this.name = params.name ?? '';
    const menuParams = params.menuItemParams as AdaptableMenuItemParams;
    const theme = menuParams.adaptableApi.themeApi.getCurrentTheme();
    this.currentTheme = theme === 'dark' ? 'dark' : 'light';
  }

  // Tell AG Grid to apply its default click / keyboard / hover behaviour
  // so this row dismisses the menu and runs AdapTable's onClick automatically.
  configureDefaults(): boolean {
    return true;
  }
}
```

**`src/app/app.module.ts`**

```ts
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';

import {AgGridModule} from 'ag-grid-angular';
import {AdaptableAngularAgGridModule} from '@adaptabletools/adaptable-angular-aggrid';
import {AppComponent} from './app.component';
import {ThemeToggleMenuItemComponent} from './theme-toggle-menu-item.component';

@NgModule({
  declarations: [AppComponent, ThemeToggleMenuItemComponent],
  imports: [BrowserModule, AgGridModule, AdaptableAngularAgGridModule],
  providers: [],
  bootstrap: [AppComponent],
  // @ts-ignore FIXME #AFL required only for Codesandbox (which uses an old rendering engine), since Ivy (Angular >9) 'entryComponents' is no longer required in standalone apps
  entryComponents: [ThemeToggleMenuItemComponent],
})
export class AppModule {}
```

<!-- /framework -->

<!-- framework: vue -->
### Vue

**Example: Context Menu: Standard Custom Items**

Standard custom Context Menu items (Vue)

- This example contains 2 standard Custom Context Menu Items:
  - **Show Dark Theme** / **Show Light Theme** — single action; hidden on row-group columns; disabled on `date` columns
  - **Dashboard** — **Show Dashboard** when the Dashboard is hidden; otherwise a sub menu with Hide and Float

Demo project (Vue); the files without a marker are shown below:

```text
public/
  index.html           [template]
src/
  adaptableOptions.ts  [template]
  agGridModules.ts     [template]
  App.vue
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  main.ts              [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  shims-vue.d.ts       [template]
  styles.css           [template]
.babelrc               [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vue).

**`src/App.vue`**

```ts
<script setup lang="ts">
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
  AdaptableOptions,
  CustomContextMenuContext,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {WebFramework} from './rowData';

const adaptableOpts: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Standard Context Menu Items Demo',
  stateOptions: {loadState: () => Promise.resolve({})},
  contextMenuOptions: {
    customContextMenu: (context: CustomContextMenuContext) => {
      const {
        defaultAgGridMenuStructure,
        defaultAdaptableMenuStructure,
        isRowGroupColumn,
        adaptableColumn,
        adaptableApi,
      } = context;

      const changeThemeMenuItem: UserContextMenuItem = {
        menuType: 'User',
        label:
          adaptableApi.themeApi.getCurrentTheme() === 'light'
            ? 'Show Dark Theme'
            : 'Show Light Theme',
        icon: {name: 'theme'},
        hidden: isRowGroupColumn,
        disabled: adaptableColumn?.dataType === 'date',
        onClick: () => {
          const {themeApi} = adaptableApi;
          themeApi.getCurrentTheme() === 'light'
            ? themeApi.loadDarkTheme()
            : themeApi.loadLightTheme();
        },
      };

      const dashboardMenuItem: UserContextMenuItem =
        adaptableApi.dashboardApi.isDashboardHidden()
          ? {
              menuType: 'User',
              label: 'Show Dashboard',
              onClick: () => adaptableApi.dashboardApi.showDashboard(),
            }
          : {
              menuType: 'User',
              label: 'Dashboard',
              subMenuItems: [
                {
                  menuType: 'User',
                  label: 'Hide Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.hideDashboard(),
                },
                {
                  menuType: 'User',
                  label: 'Float Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.floatDashboard(),
                },
              ],
            };

      return [
        changeThemeMenuItem,
        dashboardMenuItem,
        '-',
        ...defaultAgGridMenuStructure,
        '-',
        ...defaultAdaptableMenuStructure,
      ];
    },
  },
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
</script>

<template>
  <AdaptableProvider
    :gridOptions="gridOptions"
    :adaptableOptions="adaptableOpts"
    :modules="agGridModules"
    @onAdaptableReady="onAdaptableReady">
    <div style="display: flex; flex-direction: column; height: 100vh">
      <AdaptableUI />
      <AdaptableAgGridVue style="flex: 1" />
    </div>
  </AdaptableProvider>
</template>
```

## Vue Custom Menu Component

Use `frameworkComponent` on [`UserContextMenuItem`](https://www.adaptabletools.com/docs/reference/usercontextmenuitem.md) when `label`, `icon`, and `onClick` are not enough.

For example if you want a custom layout, extra controls, or live state in the shortcut area.

AG Grid owns the menu lifecycle (open, close, keyboard navigation).

- AdapTable forwards your component to AG Grid's <a href="https://www.ag-grid.com/vue-data-grid/component-menu-item/" target="_blank" rel="noreferrer">Menu Item Component</a> integration
- Use `props.menuItemParams` for [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md) and [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md)

### Providing a Custom Vue Context Menu Item

AG Grid passes menu props to your component; AdapTable adds `menuItemParams` with `adaptableApi` and `menuContext`.

Use `defineExpose({configureDefaults: () => true})` for default AG Grid menu behaviour.

```vue
<script setup lang="ts">
const props = defineProps<{
  name?: string;
  menuItemParams: {
    adaptableApi: AdaptableApi;
    menuContext: ColumnMenuContext | ContextMenuContext;
  };
}>();

defineExpose({
  configureDefaults: () => true,
});
</script>

<template>
  <div>
    <span class="ag-menu-option-part ag-menu-option-icon" role="presentation" />
    <span class="ag-menu-option-part ag-menu-option-text">{{
      props.name
    }}</span>
    <span
      class="ag-menu-option-part ag-menu-option-shortcut"
      style="opacity: 0.7">
      {{
        props.menuItemParams.adaptableApi.themeApi.getCurrentTheme() === 'dark'
          ? 'Dark'
          : 'Light'
      }}
    </span>
    <span class="ag-menu-option-part ag-menu-option-popup-pointer" />
  </div>
</template>
```

In `customContextMenu`, return a `UserContextMenuItem` with `frameworkComponent: () => ThemeToggleMenuItem`.

```ts {6}
contextMenuOptions: {
  customContextMenu: (context) => {
    const themeMenuItem: UserContextMenuItem = {
      menuType: 'User',
      label: 'Toggle Theme',
      frameworkComponent: () => ThemeToggleMenuItem,
      onClick: () => {
        const themeApi = context.adaptableApi.themeApi;
        themeApi.getCurrentTheme() === 'dark'
          ? themeApi.loadLightTheme()
          : themeApi.loadDarkTheme();
      },
    };
    return [
      themeMenuItem,
      '-',
      ...context.defaultAdaptableMenuStructure,
    ];
  },
},
```

`adaptableApi` and `menuContext` are on `props.menuItemParams`.

```ts
const {adaptableApi, menuContext} = props.menuItemParams;
const columnId = menuContext.adaptableColumn?.columnId;
```

### Anatomy of a Vue Context Menu Item Component

AG Grid passes `name`, `icon`, `disabled`, `subMenu`, `shortcut`, and `checked` to your component.

AdapTable adds on `props.menuItemParams`:

- `adaptableApi` — [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md)
- `menuContext` — [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md) or [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md)

`defineExpose({configureDefaults: () => true})` opts your row into AG Grid's default click / keyboard handling.

**Example: Context Menu: Framework Menu Row (Vue)**

Providing a Vue Component as a Custom Context Menu Item

- Theme-toggle menu item at the top of every Context Menu

Demo project (Vue); the files without a marker are shown below:

```text
public/
  index.html               [template]
src/
  agGridModules.ts         [template]
  App.vue
  columnDefs.ts            [template]
  gridOptions.ts           [template]
  main.ts                  [template]
  onAdaptableReady.ts      [template]
  rowData.ts               [template]
  shims-vue.d.ts           [template]
  styles.css               [template]
  ThemeToggleMenuItem.vue
.babelrc                   [template]
package.json               [template]
tsconfig.json              [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vue).

**`src/App.vue`**

```ts
<script setup lang="ts">
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
  AdaptableOptions,
  CustomColumnMenuContext,
  CustomContextMenuContext,
  UserColumnMenuItem,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {WebFramework} from './rowData';
import ThemeToggleMenuItem from './ThemeToggleMenuItem.vue';

const adaptableOpts: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Menu Item Demo',
  stateOptions: {loadState: () => Promise.resolve({})},
  contextMenuOptions: {
    customContextMenu: (context: CustomContextMenuContext) => {
      const themeMenuItem: UserContextMenuItem = {
        menuType: 'User',
        label: 'Toggle Theme',
        frameworkComponent: () => ThemeToggleMenuItem,
        onClick: () => {
          const themeApi = context.adaptableApi.themeApi;
          themeApi.getCurrentTheme() === 'dark'
            ? themeApi.loadLightTheme()
            : themeApi.loadDarkTheme();
        },
      };
      return [
        themeMenuItem,
        '-',
        ...context.defaultAdaptableMenuStructure,
      ];
    },
  },
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
</script>

<template>
  <AdaptableProvider
    :gridOptions="gridOptions"
    :adaptableOptions="adaptableOpts"
    :modules="agGridModules"
    @onAdaptableReady="onAdaptableReady">
    <div style="display: flex; flex-direction: column; height: 100vh">
      <AdaptableUI />
      <AdaptableAgGridVue style="flex: 1" />
    </div>
  </AdaptableProvider>
</template>
```

**`src/ThemeToggleMenuItem.vue`**

```ts
<script setup lang="ts">
import type {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-vue3-aggrid';

type AnyMenuContext = ColumnMenuContext | ContextMenuContext;

const props = defineProps<{
  // AG Grid passes the resolved label text on `name`
  name?: string;
  // AdapTable passes adaptableApi + menuContext via menuItemParams
  menuItemParams: {
    adaptableApi: AdaptableApi;
    menuContext: AnyMenuContext;
  };
}>();

// Opt-in to AG Grid's default click / keyboard / hover behaviour so this
// row dismisses the menu and runs AdapTable's onClick automatically.
defineExpose({
  configureDefaults: () => true,
});
</script>

<template>
  <div>
    <span class="ag-menu-option-part ag-menu-option-icon" role="presentation" />
    <span class="ag-menu-option-part ag-menu-option-text">
      {{ props.name }}
    </span>
    <span
      class="ag-menu-option-part ag-menu-option-shortcut"
      style="opacity: 0.7">
      {{
        props.menuItemParams.adaptableApi.themeApi.getCurrentTheme() === 'dark'
          ? 'Dark'
          : 'Light'
      }}
    </span>
    <span class="ag-menu-option-part ag-menu-option-popup-pointer" />
  </div>
</template>
```



<!-- /framework -->
