Skip to content

[UI] Right Click Menu #203

Description

@brigand

Context menus are great, and I think having it in the app would get more people to recognize that.

HTML and CSS

It's basically the same as .ui.vertical.menu, except it's hidden by default, and absolutely positioned.

<div class="ui context menu">
    <a class="item">
        Fire
    </a>
    <a class="item">
        Hide
    </a>
    <a class="item">
        Give Nickname
    </a>
</div>

<div class="employee">John</div>
<div class="employee">Rick</div>
<div class="employee">Sam</div>

Javascript

This is similar to modal. What's a better way to say "show at", i.e. with a noun instead of a preposition.

var $firstEmployee = $('.employee').first();

// show the context menu
$menu.context("show at cursor");
$menu.context("show at element", $firstEmployee);
$menu.context("show at element", $firstEmployee, "center");
$menu.context("show at element", $firstEmployee, "bottom right");

// show for employee on right-click/long-press
$menu.context("attach events", ".employee", "show");

// default settings
{
   // can be overridden explicitly when shown
   position: "auto", 

  // maximum distance from context menu edges 
  //   before closing in pixels
  // Infinity also allowed for no limit
  distance: 100,

  // clicking outside the context menu will cause it 
  //   to close if true
  closable: true,

  // allow long press for touch screens
  touch: true,

   // how long the user must press
   //   on a touch device before showing
   //   the context menu
  delay: 500  
}

For transition, scale, duration, and easing see modal.

The positions you give are suggestions, and the context menu will stick as close to them as possible without being off the screen.

For example, if you tell it to appear on the left side of an element on the left side of the screen; it will push itself right until it's on the screen edge.

If you don't specify a setting, it'll use the most spacious setting.

Context Menu

Attaching events for show binds to the contextmenu event, and prevents the default action.

This is usually triggered by a right click, but can also be triggered by pressing the AppsKey for a focused element (e.g. input).

Touch Events

If settings.touch is true, if the user holds down a bound element for settings.delay milliseconds; without dragging outside the element; the context menu will be displayed.

Callbacks

onShow() : Boolean

this is the HTMLElement.

The menu is shown. Explicitly return false to prevent the menu from showing.

onHide() : Boolean

this is the HTMLElement.

The menu is hidden. Explicitly return false to prevent the menu from hiding.

onSelect(HTMLElement chosenItem) : Boolean

this is the HTMLElement.

An item is chosen. Explicitly return false to prevent the menu from hiding.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions