Browse Source

Minor cleanup to Dropdown logic

Kirk Trombley 5 years ago
parent
commit
3b24aae2ae
1 changed files with 4 additions and 7 deletions
  1. 4 7
      client/src/components/util/GameCreationForm/Dropdown.jsx

+ 4 - 7
client/src/components/util/GameCreationForm/Dropdown.jsx

@@ -3,8 +3,8 @@ import { CSSTransition } from 'react-transition-group';
 import styles from './Dropdown.module.css';
 
 export const Item = ({ value, display, onSelect, children }) => (
-  <div className={styles.item} onClick={() => onSelect(value, display ?? value)}>
-    {children}
+  <div className={styles.item} onClick={() => onSelect(value ?? children, display ?? value ?? children)}>
+    {children ?? display ?? value}
   </div>
 );
 
@@ -21,16 +21,13 @@ export const Dropdown = ({ open, onSelect, onClick, children }) => {
     }
     let found = null;
     children.forEach(element => {
-      if (!React.isValidElement(element) || found) {
-        return;
-      }
-      if (element.props['default']) {
+      if (React.isValidElement(element) && !found && element.props['default']) {
         const { value, display } = element.props;
         found = display ?? value;
       }
     });
     setDisplayed(found);
-  }, [children, displayed])
+  }, [children, displayed]);
   return (
     <div className={styles.container}>
       <div className={styles.button} onClick={onClick}>{displayed}</div>