Skip to content

Commit d6c23f6

Browse files
committed
implement-autoScroll
1 parent cadb6ad commit d6c23f6

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎front/src/pods/student/student.component.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as classes from './student.styles';
33
// Material UI ~ components
44
import TextareaAutosize from '@material-ui/core/TextareaAutosize';
55
import Typography from '@material-ui/core/Typography';
6+
import Checkbox from '@material-ui/core/Checkbox';
7+
import FormControlLabel from '@material-ui/core/FormControlLabel';
68

79
interface Props {
810
room: string;
@@ -13,6 +15,15 @@ export const StudentComponent: React.FC<Props> = props => {
1315
const { room, log } = props;
1416
const { mainContainer, sessionName, studentBoard, labelTextarea } = classes;
1517

18+
const [autoScroll, setAutoScroll] = React.useState(false);
19+
20+
const textAreaRef = React.useRef(null);
21+
22+
React.useEffect(() => {
23+
if (!autoScroll)
24+
textAreaRef.current.scrollTop = textAreaRef.current.scrollHeight;
25+
}, [log]);
26+
1627
return (
1728
<>
1829
<main className={mainContainer}>
@@ -23,12 +34,23 @@ export const StudentComponent: React.FC<Props> = props => {
2334
Content
2435
</label>
2536
<TextareaAutosize
37+
ref={textAreaRef}
2638
id="session"
2739
rowsMax={30}
2840
rowsMin={30}
2941
className={studentBoard}
3042
value={log ?? ''}
3143
/>
44+
<FormControlLabel
45+
label="Disable AutoScroll"
46+
control={
47+
<Checkbox
48+
checked={autoScroll}
49+
onChange={e => setAutoScroll(e.target.checked)}
50+
color="primary"
51+
/>
52+
}
53+
/>
3254
</main>
3355
</>
3456
);

‎front/src/pods/trainer/components/session.component.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import ArrowForwardRoundedIcon from '@material-ui/icons/ArrowForwardRounded';
66

77
import UndoIcon from '@material-ui/icons/Undo';
88
import Button from '@material-ui/core/Button';
9+
import FormControlLabel from '@material-ui/core/FormControlLabel';
10+
import Checkbox from '@material-ui/core/Checkbox';
911

1012
interface Props {
1113
log: string;
@@ -40,8 +42,14 @@ export const SessionComponent: React.FC<Props> = props => {
4042
undoBtn,
4143
} = classes;
4244

45+
const [autoScroll, setAutoScroll] = React.useState(false);
46+
47+
const textAreaRef = React.useRef(null);
48+
4349
React.useEffect(() => {
4450
handleSetSessionContent(log);
51+
if (!autoScroll)
52+
textAreaRef.current.scrollTop = textAreaRef.current.scrollHeight;
4553
}, [log]);
4654

4755
return (
@@ -51,11 +59,22 @@ export const SessionComponent: React.FC<Props> = props => {
5159
</label>
5260

5361
<TextareaAutosize
62+
ref={textAreaRef}
5463
id="session"
5564
rowsMax={20}
5665
rowsMin={20}
5766
className={studentBoard}
5867
/>
68+
<FormControlLabel
69+
label="Disable AutoScroll"
70+
control={
71+
<Checkbox
72+
checked={autoScroll}
73+
onChange={e => setAutoScroll(e.target.checked)}
74+
color="primary"
75+
/>
76+
}
77+
/>
5978
<div className={btnContainer}>
6079
<Button
6180
variant="contained"

0 commit comments

Comments
 (0)