Next.js Discord

Discord Forum

cant type in input field

Answered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
it doesnt let me type more than 1-2 characters in the input field, but i can paste text exceeding this. Without the onchange i dont have this issue, but I want to access it from this other function. how would i fix this? I tried switching it to <input> and still same issue
const [message, setMessage] = useState<string>("");
...
  const handlePost = () => {
    console.log("Message:", message);
}
...
          <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
            <DialogContent>
...
<Label>Message</Label>
                  <Input
                    style={{ zIndex: 99 }}
                    id="message"
                    placeholder="Post."
                    type="string"
                    className="col-span-3"
                    value={message}
                    onChange={(e) => setMessage(e.target.value)}
                  />
...

              <Button onClick={() => handlePost()}>Post</Button>
...
</DialogContent>
          </Dialog>
Answered by Brown bear
ok nvm fixed it by separating dialog into its own component
View full answer

13 Replies

Asian black bear
@Brown bear Are you calling setMessage anywhere else?
Looks fine maybe try deleting .next restarting sever or incognito to see if it’s an extension causing issue?
Asian black bear
It doesn't look fine to me, in the ... there could easily be useEffect calling setMessage which would 100% screw stuff up
Thrianta
Please paste the full code
Brown bearOP
sorry for late reply
Thrianta
Looking at the full code it looks fine
Try removing the grid I doubt it but maybe a spacing issue I'll pull the code and try to reproduce later
Asiatic Lion
Please try input type="text" instead of type="string"
Brown bearOP
tried both but same issue
Brown bearOP
ok nvm fixed it by separating dialog into its own component
Answer
Brown bear
Try putting memo on the component, sometimes the parent rerenders and screw it up.