瀏覽代碼

unselect item on outside click

mightyplow 5 年之前
父節點
當前提交
f0df2a7496
共有 2 個文件被更改,包括 6 次插入3 次删除
  1. 5 2
      src/components/caloriesList/CalorieRow.tsx
  2. 1 1
      src/components/caloriesList/CaloriesList.tsx

+ 5 - 2
src/components/caloriesList/CalorieRow.tsx

@@ -1,5 +1,5 @@
 import cx from 'classnames';
-import React, { MouseEventHandler } from 'react';
+import React, { MouseEvent } from 'react';
 import styles from './calorieRow.css';
 
 type CalorieRowProps = {
@@ -15,7 +15,10 @@ function CalorieRow (props: CalorieRowProps) {
     onRowClick = Function.prototype
   } = props;
 
-  const onClick = () => onRowClick(item);
+  const onClick = (event: MouseEvent) => {
+    event.stopPropagation();
+    onRowClick(item);
+  };
 
   return (
     <div className={cx(styles.calorieRow, {[styles.selected]: isSelected})} {...{onClick}}>

+ 1 - 1
src/components/caloriesList/CaloriesList.tsx

@@ -103,7 +103,7 @@ function CaloriesList () {
       }}>
         {dayCalories.map(({date, items}) => {
           return (
-            <ItemList key={date} {...{items, selectedItem, onRowClick}} />
+            <ItemList key={date} {...{items, selectedItem, onRowClick, onClick: () => setSelectedItem() }} />
           );
         })}
       </ReactSwipe>