How to make Context Menu scrollable in React

04 Sep 20265 minutes to read

The React Context Menu component provides scrolling functionality through the enableScrolling property to manage overflow behavior when menu items exceed the available display area. This feature ensures all menu options remain accessible without disrupting page layout.

Enable scrolling by setting the enableScrolling property to true, and set the height of the popup wrapper (args.element.parentElement) in the beforeOpen event so the popup uses a fixed scrollable area.

import { enableRipple } from '@syncfusion/ej2-base';
import { ContextMenuComponent } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDom from 'react-dom';

enableRipple(true);

function App() {
  let menuItems = [
    {
      text: 'View',
      items: [
        { text: 'Mobile' },
        { text: 'Desktop Smaller' },
        { text: 'Desktop Normal' },
        { text: 'Desktop Bigger Smaller' },
        { text: 'Desktop Bigger Normal' },
      ],
    },
    { text: 'Refresh' },
    { text: 'Paste' },
    { separator: true },
    { text: 'New' },
    { text: 'Personalize' },
  ];

  return (
    <div className="container">
      <div id="target">Right click / Touch hold to open the ContextMenu</div>
      <ContextMenuComponent
        id="contextmenu"
        target="#target"
        items={menuItems}
        enableScrolling={true}
        beforeOpen={(args) => {
          args.element.parentElement.style.height = '150px';
        }}
      />
    </div>
  );
}

export default App;
ReactDom.render(<App />, document.getElementById('element'));
import { enableRipple } from '@syncfusion/ej2-base';
import { ContextMenuComponent, MenuItemModel, MenuEventArgs } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDom from 'react-dom';

enableRipple(true);

function App() {
  let menuItems: MenuItemModel[] = [
    {
      text: 'View',
      items: [
        { text: 'Mobile' },
        { text: 'Desktop Smaller' },
        { text: 'Desktop Normal' },
        { text: 'Desktop Bigger Smaller' },
        { text: 'Desktop Bigger Normal' },
      ],
    },
    { text: 'Refresh' },
    { text: 'Paste' },
    { separator: true },
    { text: 'New' },
    { text: 'Personalize' },
  ];

  return (
    <div className="container">
      <div id='target'>Right click / Touch hold to open the ContextMenu</div>
      <ContextMenuComponent
        id='contextmenu'
        target='#target'
        items={menuItems}
        enableScrolling={true}
        beforeOpen={(args: MenuEventArgs) => {
          args.element.parentElement.style.height = '150px';
        }}
      />
    </div>
  );
}
export default App;
ReactDom.render(<App />, document.getElementById('element'));