Skip to content

Remove leading and trailing Menu separators #5869

Closed

Description

@sindresorhus

OS X does this for us, but Windows and Linux does not. There's absolutely no reason to have leading and trailing separators and it's difficult to not introduce leading/trailing separators in complex context menus where multiple actors modify it. Especially when using the visible option to toggle items as the separator is not connected to that. I think Electron should handle this for us.

const electron = require('electron');

electron.app.on('ready', () => {
    electron.Menu.setApplicationMenu(electron.Menu.buildFromTemplate([{
        submenu: [{
            type: 'separator'
        }, {
            label: 'Foo'
        }, {
            type: 'separator'
        }]
    }]));

    (new electron.BrowserWindow())
        .loadURL(`https://github.com`);
});

OS X

screen shot 2016-06-04 at 14 29 49

#### Windows

screen shot 2016-06-04 at 14 29 22

##

This includes cases like this, which is annoying to have to handle manually:

[ { label: 'Unicorn' },
  { type: 'separator' },
  { label: 'Cut', role: '', visible: false },
  { label: 'Copy', role: '', visible: false },
  { label: 'Paste', role: '', visible: false } ]

screen shot 2016-06-04 at 15 22 54

## - Electron version: 1.2.1 - Operating system: OS X 10.11.5

Activity

  1. zcbenz commented on Jun 6, 2016

    @zcbenz
    Contributor

    I'm not opposed to this, but I'm not sure if there are use cases that do need leading and trailing separators.

  2. sindresorhus commented on Jun 6, 2016

    @sindresorhus
    ContributorAuthor

    @zcbenz OS X removes them, so if there are any use-cases, which I find extremely unlikely, it wouldn't work cross-platform anyways.

  3. Scazzino commented on May 6, 2017

    @Scazzino

    If the visible attribute also worked on separators then it would be trivial for us to hide them when we are hiding other items in the menu, which is often why we end up with leading/trailing separators. Just a thought.

  4. self-assigned this
    on Sep 27, 2017
  5. abhigyank commented on Jun 26, 2020

    @abhigyank

    This seems to have come back in Windows and Linux, can we re-open this?

  6. codebykat commented on Jul 31, 2020

    @codebykat

    As far as I can tell it's not documented that the visible property doesn't work on separators, would be great to get that in the docs if it is the intended behavior and not a bug. Also, you can use visible to remove an entire submenu from OSX, but Windows does not respect that.

  7. MoConWu commented on Jan 26, 2024

    @MoConWu

    This seems to have come back in Windows and Linux, can we re-open this?
    Electron,v28.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions