首页 > 解决方案 > Electron: how to make the Edit menu automatically enable/disable based on context

问题描述

I'm working on a ReactJS Electron application which has an Edit menu (as all apps do). To make it a well behaved app from a UI/UX-perspective, I want the Undo/Redo entries to automatically "go grey" when there is nothing in the buffer, and of course, become clickable when appropriate. Same for the editing entries (Cut, Copy, Paste, and Select All).

However, the clincher is that these entries should only become active when the user has brought into keyboard focus an input control, like in a form. If the focus is not on the input control (or all input controls are hidden), then the Edit menu's entries should all be grayed out.

Presently, it seems that just plopping down an Edit menu in the top bar does not automatically exhibit this sort of behavior.

Is there a built in way of doing this in Electron, or does one have to "hand do it" for each possible control that can appear? In other words, do I have to add an event to each control on each form?

标签: javascriptnode.jsreactjsmenuelectron

解决方案


推荐阅读