Skip to content

PopupOptions incorrectly requires y #54

Closed

Description

@shiftkey

The docs for Menu.popup(window, options) https://electron.atom.io/docs/api/menu/#menupopupbrowserwindow-options generates this definition for PopupOptions:

  interface PopupOptions {
    /**
     * Default is the current mouse cursor position.
     */
    x?: number;
    /**
     * ( if x is used) Default is the current mouse cursor position.
     */
    y: number;
    /**
     * Set to true to have this method return immediately called, false to return after
     * the menu has been selected or closed. Defaults to false.
     */
    async?: boolean;
    /**
     * The index of the menu item to be positioned under the mouse cursor at the
     * specified coordinates. Default is -1.
     */
    positioningItem?: number;
  }

The required y here doesn't reflect the correct state (x and y are undefined, or x and y are defined).

This breaks GitHub Desktop's usage, because we don't care about the location:

const window = BrowserWindow.fromWebContents(event.sender)
menu.popup(window, { async: true })

This works around the issue, but might be able to be simplified down:

  interface PopupOptionsLocation {
    /**
     * Default is the current mouse cursor position.
     */
    x: number;
    /**
     * ( if x is used) Default is the current mouse cursor position.
     */
    y: number;
    /**
     * Set to true to have this method return immediately called, false to return after
     * the menu has been selected or closed. Defaults to false.
     */
    async?: boolean;
    /**
     * The index of the menu item to be positioned under the mouse cursor at the
     * specified coordinates. Default is -1.
     */
    positioningItem?: number;
  }

  interface PopupOptionsNoLocation {
    /**
     * Set to true to have this method return immediately called, false to return after
     * the menu has been selected or closed. Defaults to false.
     */
    async?: boolean;
    /**
     * The index of the menu item to be positioned under the mouse cursor at the
     * specified coordinates. Default is -1.
     */
    positioningItem?: number;
  }

  type PopupOptions = PopupOptionsLocation | PopupOptionsNoLocation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions