소스 검색

Go to selection mode after adding a shape

Christopher Chedeau 5 년 전
부모
커밋
ab84b5a048
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      src/index.js

+ 12 - 1
src/index.js

@@ -144,6 +144,12 @@ function setSelection(selection) {
   });
 }
 
+function clearSelection() {
+  elements.forEach(element => {
+    element.isSelected = false;
+  });
+}
+
 function App() {
   const [draggingElement, setDraggingElement] = React.useState(null);
   const [elementType, setElementType] = React.useState("selection");
@@ -188,7 +194,11 @@ function App() {
         <input
           type="radio"
           checked={elementType === type}
-          onChange={() => setElementType(type)}
+          onChange={() => {
+            setElementType(type);
+            clearSelection();
+            drawScene();
+          }}
         />
         {children}
       </label>
@@ -247,6 +257,7 @@ function App() {
             elements.pop();
             setSelection(draggingElement);
           }
+          setElementType("selection");
           drawScene();
         }}
         onMouseMove={e => {