mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-30 04:18:28 +08:00
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
|
import React, { useRef } from 'react';
|
||
|
import { Button, InputNumber, Space } from 'antd';
|
||
|
import type { InputNumberRef } from 'rc-input-number';
|
||
|
|
||
|
const App: React.FC = () => {
|
||
|
const inputRef = useRef<InputNumberRef>(null);
|
||
|
|
||
|
return (
|
||
|
<Space direction="vertical" style={{ width: '100%' }}>
|
||
|
<Space wrap>
|
||
|
<Button
|
||
|
onClick={() => {
|
||
|
inputRef.current!.focus({
|
||
|
cursor: 'start',
|
||
|
});
|
||
|
}}
|
||
|
>
|
||
|
Focus at first
|
||
|
</Button>
|
||
|
<Button
|
||
|
onClick={() => {
|
||
|
inputRef.current!.focus({
|
||
|
cursor: 'end',
|
||
|
});
|
||
|
}}
|
||
|
>
|
||
|
Focus at last
|
||
|
</Button>
|
||
|
<Button
|
||
|
onClick={() => {
|
||
|
inputRef.current!.focus({
|
||
|
cursor: 'all',
|
||
|
});
|
||
|
}}
|
||
|
>
|
||
|
Focus to select all
|
||
|
</Button>
|
||
|
<Button
|
||
|
onClick={() => {
|
||
|
inputRef.current!.focus({
|
||
|
preventScroll: true,
|
||
|
});
|
||
|
}}
|
||
|
>
|
||
|
Focus prevent scroll
|
||
|
</Button>
|
||
|
</Space>
|
||
|
<InputNumber style={{ width: '100%' }} defaultValue={999} ref={inputRef} />
|
||
|
</Space>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default App;
|