Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion client/src/components/VotingComponents/VotingPopup.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/prop-types */
import { makeStyles } from '@material-ui/core/styles'
import { useState, useEffect } from 'react'
import { useState, useEffect, useRef } from 'react'

import {
Paper,
Expand Down Expand Up @@ -50,6 +50,8 @@ const useStyles = makeStyles((theme) => ({
input: {
color: '#3c4858cc',
paddingBottom: 1,
minHeight: 50,
fontSize: '1rem',
'&::before': {
pointerEvents: 'auto',
},
Expand All @@ -71,6 +73,7 @@ const VotingPopup = ({
const [expand, setExpand] = useState({ open: false, type: '' })
const [comment, setComment] = useState('')
const [checkWindowWidth, setCheckWindowWidth] = useState(true)
const commentInputRef = useRef(null)

const handleWindowSizeChange = () => {
if (window.innerWidth < 400) {
Expand Down Expand Up @@ -130,6 +133,10 @@ const VotingPopup = ({
const selectionPopover = document.querySelector('#popButtons')
if (selectionPopover) {
const handleMouseDown = (e) => {
const tag = e.target.tagName.toLowerCase()
if (tag === 'input' || tag === 'textarea') {
return
}
e.preventDefault()
}
selectionPopover.addEventListener('mousedown', handleMouseDown)
Expand All @@ -141,6 +148,17 @@ const VotingPopup = ({
}
}, [])

useEffect(() => {
if (expand.open && expand.type === 'comment' && commentInputRef.current) {
const timer = setTimeout(() => {
if (commentInputRef.current) {
commentInputRef.current.focus()
}
}, 300)
return () => clearTimeout(timer)
}
}, [expand.open, expand.type])

let inputValue = comment

const isComment = expand.type === 'comment'
Expand Down Expand Up @@ -281,6 +299,7 @@ const VotingPopup = ({
<Input
placeholder="Type comment here"
className={classes.input}
inputRef={commentInputRef}
endAdornment={(
<InputAdornment position="end">
<Button
Expand Down