简体   繁体   English

Material-ui:警告:未知的事件处理程序属性`onKeyboardFocus`。它会被忽略

[英]Material-ui: Warning: Unknown event handler property `onKeyboardFocus`. It will be ignored

More detailed trace: 更详细的追踪:

warning.js:33 Warning: Unknown event handler property `onKeyboardFocus`. It will be ignored.
    in div (created by IconMenu)
    in div (created by IconMenu)
    in IconMenu (created by DropdownMenu)
    in div (created by DropdownMenu)

I have an IconMenu with a an IconButtonElement prop. 我有一个带有IconButtonElement道具的IconMenu。 For some reason it keeps throwing this warning. 出于某种原因,它一直在抛出这个警告。 Why? 为什么? What is it? 它是什么?

Sample code that triggers is: 触发的示例代码是:

<IconMenu
    iconButtonElement={
        <div>
            <IconButton onClick={this.handleTouchTap}>
                <div >
                    <img src={require("../../settingsicon.svg")}/>
                </div>
            </IconButton>
        </div>}
    open={this.state.open}
    anchorOrigin={{horizontal: "right", vertical: "bottom"}}
    targetOrigin={{horizontal: "right", vertical: "top"}}
>
    <MenuItem
        className={someClass}
        onClick={this.handleLogOutClick}
    >
        <span className={someClass}Hello</span>
    </MenuItem>
    <Divider className={someClass}/>
    <MenuItem className={someClass}>
        <span className={someClass}>Goodbye</span>
    </MenuItem>
</IconMenu>

It's a pretty simple example almost copy-pasted from the documentation with a few functions to the menuitems, but nothing that should throw an error such as this. 这是一个非常简单的例子,几乎从带有一些函数的文档中复制粘贴到菜单项,但没有任何东西应该抛出这样的错误。 Even when I made a complete barebone example - it still throws the warning. 即使我做了一个完整的准系统示例 - 它仍然会发出警告。 It's a bit ugly to have in the console every time the page loads :) 每次页面加载时都在控制台中有点难看:)

IconMenu passes the onKeyboardFocus prop to the element defined in iconButtonElement , which would be fine if it were a React component (like IconButton, as the docs suggest), but the warning occurs because you've wrapped it in a div and onKeyboardFocus isn't a supported DOM event (it is a property in the IconButton API). IconMenu传递onKeyboardFocus道具中定义的元素iconButtonElement ,这将是罚款,如果它是一个作出反应成分(如IconButton,作为该文档建议),但出现警告,因为你已经在一个div包裹它,onKeyboardFocus不受支持的DOM事件(它是IconButton API中的属性)。

You should remove the outer div in iconButtonElement . 您应该删除iconButtonElement中的外部div。

onKeyboardFocus defaults to a no-op function and is passed unconditionally. onKeyboardFocus默认为无操作函数,无条件传递。 Since you aren't specifying it as a prop for IconMenu the effect will be the same if you remove the wrapping div in iconButtonElement: it'll do nothing, but the warning will no longer occur. 由于你没有将它指定为IconMenu的道具,如果你在iconButtonElement中移除包装div,效果将是相同的:它什么也不做,但警告将不再发生。

If you were using the onKeyboardFocus prop, removing the div or replacing it with another component that passes this prop to its child would be the only ways to ensure that it gets to IconButton. 如果您正在使用onKeyboardFocus道具,删除div或将其替换为将此道具传递给其子项的其他组件将是确保它到达IconButton的唯一方法。

I wouldn't submit an issue, as a couple have already been submitted and closed: 我不会提交问题,因为已经提交并关闭了一对夫妇:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:未知的事件处理程序属性“onValueChange”。 它会被忽略 - Warning: Unknown event handler property `onValueChange`. It will be ignored 警告:未知的事件处理程序属性“onHeaderClick”。 它会被忽略 - Warning: Unknown event handler property `onHeaderClick`. It will be ignored 为什么警告:未知事件处理程序属性`onSession`显示在 React 应用程序中? - Why the warning: Unknown event handler property `onSession` is displayed in React app? Material-UI Drawer不会关闭,Chrome会显示警告:on未知prop`onRequestChange` <div> 标签 - Material-UI Drawer will not close and chrome shows a Warning: Unknown prop `onRequestChange` on <div> tag 反应 Material-UI 和颜色:警告 - React Material-UI and color: warning 如何在事件处理程序的 mui 数据表中使用 material-ui 菜单 - How to use a material-ui Menu inside a mui-datatable on event handler 未知道具-React和Material-UI - Unknown props - react and material-ui Material-UI的TextField验证和onChange事件处理程序似乎没有按预期工作 - Material-UI's TextField validation and onChange event handler don't seem to work as expected 为什么 Material-UI 按钮的值未传递给 onClick 事件处理程序? - Why value from a Material-UI Button is not being passed to the onClick event handler? Material-ui覆盖StepLabel嵌套属性 - Material-ui Override StepLabel nested property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM