Bug 1474234 - Don't pass internal props onto child button in MenuButton; r=jdescottes
authorBrian Birtles <birtles@gmail.com>
Thu, 02 Aug 2018 09:59:24 +0900
changeset 826227 2d0225ff21ff1238cf61e4a3c239dd89b7b7fc25
parent 826226 4c9740da28ee579f62463510226f405711b33b5e
child 826228 d4ca2c8982afbcac4494d91b65cff5c64e59498a
push id118275
push userbmo:dharvey@mozilla.com
push dateFri, 03 Aug 2018 11:44:33 +0000
reviewersjdescottes
bugs1474234
milestone63.0a1
Bug 1474234 - Don't pass internal props onto child button in MenuButton; r=jdescottes Otherwise we will get errors like: console.error: "Warning: React does not recognize the `menuId` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `menuid` instead. If you accidentally passed it from a parent component, remove it from the DOM element.\n in button (created by MenuButton)\n in MenuButton (created by ToolboxToolbar)\n in div (created by ToolboxToolbar)\n in div (created by ToolboxToolbar)\n in ToolboxToolbar (created by ToolboxController)\n in ToolboxController" console.error: "Warning: React does not recognize the `menuPosition` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `menuposition` instead. If you accidentally passed it from a parent component, remove it from the DOM element.\n in button (created by MenuButton)\n in MenuButton (created by ToolboxToolbar)\n in div (created by ToolboxToolbar)\n in div (created by ToolboxToolbar)\n in ToolboxToolbar (created by ToolboxController)\n in ToolboxController" console.error: "Warning: React does not recognize the `menuOffset` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `menuoffset` instead. If you accidentally passed it from a parent component, remove it from the DOM element.\n in button (created by MenuButton)\n in MenuButton (created by ToolboxToolbar)\n in div (created by ToolboxToolbar)\n in div (created by ToolboxToolbar)\n in ToolboxToolbar (created by ToolboxController)\n in ToolboxController" It's also not what we intend to do. Differential Revision: https://phabricator.services.mozilla.com/D2640
devtools/client/shared/components/menu/MenuButton.js
--- a/devtools/client/shared/components/menu/MenuButton.js
+++ b/devtools/client/shared/components/menu/MenuButton.js
@@ -12,16 +12,25 @@ const PropTypes = require("devtools/clie
 const ReactDOM = require("devtools/client/shared/vendor/react-dom");
 const Services = require("Services");
 const dom = require("devtools/client/shared/vendor/react-dom-factories");
 const { button } = dom;
 const {
   HTMLTooltip,
 } = require("devtools/client/shared/widgets/tooltip/HTMLTooltip");
 
+// Return a copy of |obj| minus |fields|.
+const omit = (obj, fields) => {
+  const objCopy = { ...obj };
+  for (const field of fields) {
+    delete objCopy[field];
+  }
+  return objCopy;
+};
+
 class MenuButton extends PureComponent {
   static get propTypes() {
     return {
       // The document to be used for rendering the menu popup.
       doc: PropTypes.object.isRequired,
 
       // An optional ID to assign to the menu's container tooltip object.
       menuId: PropTypes.string,
@@ -261,17 +270,19 @@ class MenuButton extends PureComponent {
     //
     // Bug 1472942: Do this for all users of HTMLTooltip.
     const menu = ReactDOM.createPortal(
       this.props.children,
       this.tooltip.panel
     );
 
     const buttonProps = {
-      ...this.props,
+      // Pass through any props set on the button, except the ones we handle
+      // here.
+      ...omit(this.props, Object.keys(MenuButton.propTypes)),
       onClick: this.onClick,
       "aria-expanded": this.state.expanded,
       "aria-haspopup": "menu",
       ref: this.setButtonRef,
     };
 
     if (this.state.expanded) {
       buttonProps.onKeyDown = this.onKeyDown;