官方文档: https://4x-ant-design.antgroup.com/components/input-cn
This example demonstrates how to use the Input component in Ant Design React.
import React, { useState } from 'react';
import { Input } from 'antd';
function App() {
const [value, setValue] = useState('');
return (
<Input
placeholder="Enter text"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
}
import React from 'react';
import { Input } from 'antd';
function App() {
return (
<>
<Input size="large" placeholder="Large size" />
<Input placeholder="Default size" />
<Input size="small" placeholder="Small size" />
</>
);
}
import React from 'react';
import { Input } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
function App() {
return (
<>
<Input
prefix={<UserOutlined />}
placeholder="Username"
/>
<Input
prefix={<LockOutlined />}
type="password"
placeholder="Password"
/>
</>
);
}
import React from 'react';
import { Input } from 'antd';
function App() {
return <Input.Password placeholder="Enter password" />;
}
import React from 'react';
import { Input } from 'antd';
const { Search } = Input;
function App() {
const onSearch = (value) => {
console.log('Search:', value);
};
return (
<Search
placeholder="Search"
onSearch={onSearch}
enterButton
/>
);
}
import React from 'react';
import { Input } from 'antd';
const { TextArea } = Input;
function App() {
return (
<TextArea
rows={4}
placeholder="Enter text"
showCount
maxLength={100}
/>
);
}
import React from 'react';
import { Input } from 'antd';
const { Group, Addon } = Input;
function App() {
return (
<>
<Input.Group compact>
<Input style={{ width: '20%' }} defaultValue="0571" />
<Input style={{ width: '80%' }} defaultValue="26888888" />
</Input.Group>
</>
);
}
Input for text inputInput.Password for password inputInput.Search for search inputInput.TextArea for multi-line inputprefix and suffix for iconssize prop for input sizeshowCount for character countmaxLength to limit input length