Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Popover/Chip demo runtime error #20175

Closed
1 of 2 tasks
adamdicarlo opened this issue Mar 19, 2020 · 2 comments · Fixed by #20265
Closed
1 of 2 tasks

[docs] Popover/Chip demo runtime error #20175

adamdicarlo opened this issue Mar 19, 2020 · 2 comments · Fixed by #20265
Labels
bug 🐛 Something doesn't work docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@adamdicarlo
Copy link

The page at https://material-ui.com/components/popover/ has a demo that crashes when using the anchorPosition.top and anchorPosition.left controls.

Perhaps #17101 did not actually fix the bug.

  • The issue is present in the latest release. ??? I'm not sure what release is used on the live website.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Click either the down arrow or up arrow of either anchorPositon.top or anchorPosition.left twice and the demo crashes with this message:

This demo had a runtime error!

We would appreciate it if you report this error directly to our issue tracker.

TypeError: e.target is null

Expected Behavior 🤔

I should be able to change those values more than once and the demo should never crash.

Steps to Reproduce 🕹

  1. Visit https://material-ui.com/components/popover/
  2. Scroll down to Anchor Playground
  3. Click either anchorPosition control twice, or click one once, and the other once.

2020-03-18 17 50 16

Your Environment 🌎

Firefox on macOS.

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Mar 19, 2020
@oliviertassinari
Copy link
Member

@adamdicarlo Thanks for reporting this problem. It's my fault, I was too eager in my changes in #20111. I would propose the following patch: do you want to work on it? :)

diff --git a/docs/src/pages/components/chips/ChipsPlayground.js b/docs/src/pages/components/chips/ChipsPlayground.js
index cada04484..610cf1357 100644
--- a/docs/src/pages/components/chips/ChipsPlayground.js
+++ b/docs/src/pages/components/chips/ChipsPlayground.js
@@ -24,7 +24,7 @@ const styles = theme => ({

 function ChipsPlayground(props) {
   const { classes } = props;
-  const [{ color, onDelete, avatar, icon, variant, size }, setState] = React.useState({
+  const [state, setState] = React.useState({
     color: 'default',
     onDelete: 'none',
     avatar: 'none',
@@ -32,12 +32,13 @@ function ChipsPlayground(props) {
     variant: 'default',
     size: 'medium',
   });
+  const { color, onDelete, avatar, icon, variant, size } = state;

   const handleChange = event => {
-    setState(state => ({
+    setState({
       ...state,
       [event.target.name]: event.target.value,
-    }));
+    });
   };

   const handleDeleteExample = () => {
diff --git a/docs/src/pages/components/popover/AnchorPlayground.js b/docs/src/pages/components/popover/AnchorPlayground.js
index d29b01ea0..56aee3a96 100644
--- a/docs/src/pages/components/popover/AnchorPlayground.js
+++ b/docs/src/pages/components/popover/AnchorPlayground.js
@@ -68,19 +68,7 @@ function AnchorPlayground(props) {
   const { classes } = props;
   const anchorRef = React.useRef();

-  const [
-    {
-      open,
-      anchorOriginVertical,
-      anchorOriginHorizontal,
-      transformOriginVertical,
-      transformOriginHorizontal,
-      positionTop,
-      positionLeft,
-      anchorReference,
-    },
-    setState,
-  ] = React.useState({
+  const [state, setState] = React.useState({
     open: false,
     anchorOriginVertical: 'top',
     anchorOriginHorizontal: 'left',
@@ -90,33 +78,43 @@ function AnchorPlayground(props) {
     positionLeft: 400, // Same as above
     anchorReference: 'anchorEl',
   });
+  const {
+    open,
+    anchorOriginVertical,
+    anchorOriginHorizontal,
+    transformOriginVertical,
+    transformOriginHorizontal,
+    positionTop,
+    positionLeft,
+    anchorReference,
+  } = state;

   const handleChange = event => {
-    setState(state => ({
+    setState({
       ...state,
       [event.target.name]: event.target.value,
-    }));
+    });
   };

   const handleNumberInputChange = key => event => {
-    setState(state => ({
+    setState({
       ...state,
       [key]: parseInt(event.target.value, 10),
-    }));
+    });
   };

   const handleClickButton = () => {
-    setState(state => ({
+    setState({
       ...state,
       open: true,
-    }));
+    });
   };

   const handleClose = () => {
-    setState(state => ({
+    setState({
       ...state,
       open: false,
-    }));
+    });
   };

   let mode = '';

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work good first issue Great for first contributions. Enable to learn the contribution process. labels Mar 19, 2020
@oliviertassinari oliviertassinari changed the title Popover demo runtime error (again?) [docs] Popover/Chip demo runtime error Mar 19, 2020
@Zaynex
Copy link
Contributor

Zaynex commented Mar 25, 2020

Still meet problem but not the same message.
Kapture 2020-03-25 at 13 12 21

Zaynex pushed a commit to Zaynex/material-ui that referenced this issue Mar 25, 2020
Zaynex added a commit to Zaynex/material-ui that referenced this issue Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants