Browse Source

select only one check per row

amenpunk 2 years ago
parent
commit
55d513c6f5
1 changed files with 38 additions and 26 deletions
  1. 38 26
      src/Components/Test/Cleaver/Question.jsx

+ 38 - 26
src/Components/Test/Cleaver/Question.jsx

1
 import * as React from 'react';
1
 import * as React from 'react';
2
 
2
 
3
-import { 
4
-  Remove as RemoveIcon,
5
-  Add as AddIcon
6
-} from '@mui/icons-material';
7
-
3
+import { Remove as RemoveIcon, Add as AddIcon } from '@mui/icons-material';
8
 import {
4
 import {
9
   Card,CardContent,Avatar,Checkbox,List,Tooltip,
5
   Card,CardContent,Avatar,Checkbox,List,Tooltip,
10
   ListItem,ListItemButton,ListItemIcon,ListItemText
6
   ListItem,ListItemButton,ListItemIcon,ListItemText
11
 } from '@mui/material'
7
 } from '@mui/material'
12
-
13
 import { deepPurple } from '@mui/material/colors';
8
 import { deepPurple } from '@mui/material/colors';
14
 
9
 
15
 function CheckboxexHeader(prop) {
10
 function CheckboxexHeader(prop) {
33
 
28
 
34
 function CheckboxesGroup(props) {
29
 function CheckboxesGroup(props) {
35
 
30
 
36
-  const [checked, setChecked] = React.useState([0]);
31
+  const [checkA, setCheckA] = React.useState(0);
32
+  const [checkB, setCheckB] = React.useState(0);
37
 
33
 
38
-  const handleToggle = (value) => () => {
39
 
34
 
40
-    const currentIndex = checked.indexOf(value);
41
-    const newChecked = [...checked];
42
-    if (currentIndex === -1) {
43
-      newChecked.push(value);
44
-    } else {
45
-      newChecked.splice(currentIndex, 1);
35
+  const changeA = (event) => {
36
+    let { id } = event.target
37
+    if(parseInt( checkB ) !== parseInt(id) ){
38
+      setCheckA(parseInt( id ))
39
+    }
40
+  };
41
+  
42
+  const changeB = (event) => {
43
+    let { id } = event.target
44
+    if(parseInt( checkA ) !== parseInt( id )){
45
+      setCheckB(parseInt( id ))
46
     }
46
     }
47
-
48
-    setChecked(newChecked);
49
   };
47
   };
50
 
48
 
51
   return (
49
   return (
52
     <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
50
     <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
51
+
53
       {props.quiz.map((value) => {
52
       {props.quiz.map((value) => {
53
+
54
         const labelId = `checkbox-list-label-${value.id}`;
54
         const labelId = `checkbox-list-label-${value.id}`;
55
+
55
         return (
56
         return (
56
           <ListItem key={value.id}>
57
           <ListItem key={value.id}>
57
-            <ListItemButton role={undefined} onClick={handleToggle(value)} dense>
58
+            <ListItemButton dense>
58
               <Tooltip title={value.decription} placement="top-start" arrow>
59
               <Tooltip title={value.decription} placement="top-start" arrow>
59
                 <ListItemText 
60
                 <ListItemText 
60
-                  sx={{ '& .MuiTypography-root' : {
61
+                  sx={{ 
62
+                    '& .MuiTypography-root' : {
61
                       fontWeight:'bold'
63
                       fontWeight:'bold'
62
-                  }}} className="checkbox_label_question" id={labelId} primary={value.nombre} />
64
+                  }}} 
65
+                  className="checkbox_label_question" 
66
+                  id={labelId} 
67
+                  primary={value.nombre} 
68
+                 />
63
               </Tooltip>
69
               </Tooltip>
64
 
70
 
65
               <ListItemIcon>
71
               <ListItemIcon>
66
                 <Checkbox
72
                 <Checkbox
73
+                  id={value.id.toString()}
74
+                  sx={{ '& .MuiSvgIcon-root': { fontSize: 28 } }}
75
+                  color="error"
67
                   edge="start"
76
                   edge="start"
68
-                  checked={checked.indexOf(value) !== -1}
69
-                  tabIndex={-1}
70
                   disableRipple
77
                   disableRipple
71
-                  inputProps={{ 'aria-labelledby': labelId }}
78
+                  inputProps={{ 'aria-labelledby': value.id }}
79
+                  checked={parseInt( checkA ) === parseInt( value.id )}
80
+                  onChange={changeA}
72
                 />
81
                 />
73
               </ListItemIcon>
82
               </ListItemIcon>
74
               <ListItemIcon>
83
               <ListItemIcon>
75
                 <Checkbox
84
                 <Checkbox
85
+                  id={value.id.toString()}
86
+                  sx={{ '& .MuiSvgIcon-root': { fontSize: 28 } }}
87
+                  color="error"
76
                   edge="start"
88
                   edge="start"
77
-                  //checked={}
78
-                  tabIndex={-1}
79
                   disableRipple
89
                   disableRipple
80
-                  inputProps={{ 'aria-labelledby': labelId }}
90
+                  inputProps={{ 'aria-labelledby': value.id }}
91
+                  checked={parseInt( checkB ) === parseInt( value.id )}
92
+                  onChange={changeB}
81
                 />
93
                 />
82
               </ListItemIcon>
94
               </ListItemIcon>
83
             </ListItemButton>
95
             </ListItemButton>
88
   );
100
   );
89
 }
101
 }
90
 
102
 
91
-export function Question({ quiz}) {
103
+export function Question({quiz}) {
92
   let { instrucciondepregunta, respuestas,id } = quiz
104
   let { instrucciondepregunta, respuestas,id } = quiz
93
   return (
105
   return (
94
     <Card sx={{ minWidth: 275, margin: '30px !important', borderLeft: '5px solid var(--main)'}}>
106
     <Card sx={{ minWidth: 275, margin: '30px !important', borderLeft: '5px solid var(--main)'}}>