mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
6380fc7a95
* feat: improve focus behavior * test: update snapshot * chore(deps): bump rc-input-number version * chore: remove useless code * test: update snapshot
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;
|