Chrome扩展程序:网络面板-需要禁用默认问号触发帮助行为

时间:2019-01-17 21:52:19

标签: google-chrome google-chrome-extension

我正在开发添加自定义devtools面板的Chrome扩展程序。我的面板上有一些允许用户输入的文本框,但是,每当我输入问号时,它都会打开Chrome帮助,而不是打出“?”字符。有没有办法阻止这种行为?

更新: 我应该提到我在扩展中使用React,并且正在使用React的综合事件。

1 个答案:

答案 0 :(得分:0)

This turned out to be unrelated to Chrome and due to a React JS nuance.

I was trying to call event.stopPropagation() on a React synthetic event which doesn't actually stop propagation to non-react registered event handlers such as the one that opens the help dialog.

The fix was to register a keydown event to the native DOM element and calling stopPropagation on the native event. This properly stoped the help menu from opening in response to typing in my input.

e.g.

<input 
  ref={input => input.addEventListener(event => event.stopPropagation())}
  onChange={this.myOnChangeHandler}
  />