MenuItem
Class: MenuItem
ネイティブアプリケーションメニューとコンテキストメニューに項目を追加します。
Process: Main
See Menu
for examples.
[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
new MenuItem(options)
acceleratorWorksWhenHidden
is specified as being macOS-only because accelerators always work when items are hidden on Windows and Linux. これはネイティブの macOS 開発では可能なので、オプションを無効にするオプションをユーザーに提供するためにユーザーに公開されます。
インスタンスプロパティ
MenuItem
のインスタンスには以下のプロパティがあります。
menuItem.id
A string
indicating the item's unique id. This property can be dynamically changed.
menuItem.label
そのアイテムに表示されるラベルを示す string
。
menuItem.click
MenuItem がクリックイベントを受け取った時に発火される Function
。 これは menuItem.click(event, focusedWindow, focusedWebContents)
で呼び出されます。
event
KeyboardEventfocusedWindow
BaseWindowfocusedWebContents
WebContents
menuItem.submenu
存在する場合、メニューアイテムのサブメニューを格納する Menu
(任意)。
menuItem.type
そのアイテムの種類を示す string
。 Can be normal
, separator
, submenu
, checkbox
, radio
, header
or palette
.
header
and palette
are only available on macOS 14 and up.
menuItem.role
セットされている場合、アイテムの役割を示す string
(任意)。 undo
, redo
, cut
, copy
, paste
, pasteAndMatchStyle
, delete
, selectAll
, reload
, forceReload
, toggleDevTools
, resetZoom
, zoomIn
, zoomOut
, toggleSpellChecker
, togglefullscreen
, window
, minimize
, close
, help
, about
, services
, hide
, hideOthers
, unhide
, quit
, startSpeaking
, stopSpeaking
, zoom
, front
, appMenu
, fileMenu
, editMenu
, viewMenu
, shareMenu
, recentDocuments
, toggleTabBar
, selectNextTab
, selectPreviousTab
, showAllTabs
, mergeAllWindows
, clearRecentDocuments
, moveTabToNewWindow
, windowMenu
のいずれかにできます。
menuItem.accelerator
Accelerator
(任意) 型で、セットされているならばそのアイテムのアクセラレータになります。
menuItem.userAccelerator
Readonly macOS
Accelerator | null
型で、メニューアイテムの ユーザーが割り当てたアクセラレータ を表します。
[!NOTE] This property is only initialized after the
MenuItem
has been added to aMenu
.Menu.buildFromTemplate
またはMenu.append()/insert()
を介してください。 初期化前にアクセスするとnull
を返します。
menuItem.icon
セットされている場合、アイテムのアイコンを示す NativeImage | string
(任意)。
menuItem.sublabel
そのアイテムのサブラベルを示す string
。
menuItem.toolTip
macOS
そのアイテムに浮かび上がるテキストを示す string
。
menuItem.enabled
A boolean
indicating whether the item is enabled. This property can be dynamically changed.
menuItem.visible
A boolean
indicating whether the item is visible. This property can be dynamically changed.
menuItem.checked
A boolean
indicating whether the item is checked. This property can be dynamically changed.
checkbox
メニューアイテムは、選択された時に checked
プロパティをオンかオフにトグル切り替えします。
radio
メニューアイテムは、クリックされると checked
がオンになり、同じメニュー内の隣接するアイテムすべてのこのプロパティをオフにします。
更なる動作は、click
関数の追加で可能です。
menuItem.registerAccelerator
boolean
型で、アクセラレータをシステムに登録する必要があるのか、ただ表示するだけなのかを示します。
このプロパティは動的に変更できます。
menuItem.sharingItem
macOS
SharingItem
型で、role
が shareMenu
の場合に共有するアイテムを示します。
このプロパティは動的に変更できます。
menuItem.commandId
アイテムの一意な連番 id を示す number
。
menuItem.menu
そのアイテムが属する Menu
。