geist-org / geist-ui

A design system for building modern websites and applications.
https://geist-ui.dev
MIT License
4.35k stars 335 forks source link

input/textarea state not change #750

Closed chyroc closed 2 years ago

chyroc commented 2 years ago

image

import {Button, Input, Text, Textarea} from "@geist-ui/core";
import {useState} from "react";

export default function IndexPage() {
  const [title, setTitle] = useState("");
  const [content, setContent] = useState("");
  return (
    <div style={{margin: 30}}>
      <Text>
        <Text span style={{marginRight: 10}}>标题:</Text>
        <Input placeholder="标题" onClick={e => setTitle(e.target.value)}/>
      </Text>

      <Text>
        <Text span style={{marginRight: 10}}>内容:</Text>
        <Textarea width="200" onClick={e => setContent(e.target.value)}/>
      </Text>

      <Button auto onClick={() => {
        console.log({title, content})
      }}>提交</Button>
    </div>
  )
}
unix commented 2 years ago

You need change onClick to onChange for capture the value changes:

<Textarea width="200" onChange={e => setContent(e.target.value)}/>

codesandbox example