Skip to main content

Customizing context menus

9. Weight and id

The last two properties of a registry item are weight and id.

Weight

The weight property is a number that determines the order of the options in the context menu. A higher number means your option will be lower in the list.

Test this by updating the weight property on one of your new registry items and confirming that the corresponding option moves to the top or bottom of the list.

Note that weight does not have to be positive or integer-valued.

Id

Every registry item has an id that can be used to unregister it. You can use this to get rid of registry items that you don't want.

For instance, you can remove the item that deletes all blocks on the workspace:

Blockly.ContextMenuRegistry.registry.unregister('workspaceDelete');

Default items

For a list of the default registry items that Blockly provides, look at contextmenu_items.ts. Each entry contains both the id and the weight.