@gm-pc/keyboard 1.27.1-beta.0 → 1.27.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/cell/auto_complete.tsx +79 -79
- package/src/cell/cell.tsx +27 -27
- package/src/cell/date_picker.tsx +73 -73
- package/src/cell/input.tsx +75 -75
- package/src/cell/input_number.tsx +92 -92
- package/src/cell/level_select.tsx +70 -70
- package/src/cell/more_select.tsx +83 -83
- package/src/cell/select.tsx +70 -70
- package/src/cell/table_select.tsx +70 -70
- package/src/core/cell.tsx +96 -96
- package/src/core/wrap.tsx +253 -253
- package/src/hoc/keyboard_table_x.tsx +121 -121
- package/src/index.ts +22 -22
- package/src/stories.tsx +308 -308
- package/src/types.ts +87 -87
- package/src/utils/constant.ts +21 -21
- package/src/utils/context.ts +4 -4
- package/src/utils/do_focus.ts +14 -14
- package/src/utils/get_column_key.ts +11 -11
- package/src/utils/get_key.ts +8 -8
- package/src/utils/index.ts +8 -8
- package/src/utils/is_input_un_boundary.ts +29 -29
- package/src/utils/scroll_into_view_fixed_width.ts +71 -71
- package/src/utils/use_context_data.ts +12 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-pc/keyboard",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.2-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-pc#readme",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@gm-common/tool": "^2.10.0",
|
|
30
|
-
"@gm-pc/react": "^1.27.
|
|
31
|
-
"@gm-pc/table-x": "^1.27.
|
|
30
|
+
"@gm-pc/react": "^1.27.2-beta.0",
|
|
31
|
+
"@gm-pc/table-x": "^1.27.2-beta.0",
|
|
32
32
|
"classnames": "^2.2.5",
|
|
33
33
|
"lodash": "^4.17.19"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "74161c54d70abebf6cd6b6f2dbbb1298841579e2"
|
|
36
36
|
}
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import React, { FC, useRef, FocusEvent, KeyboardEvent } from 'react'
|
|
2
|
-
import { AutoComplete, AutoCompleteRef, AutoCompleteProps } from '@gm-pc/react'
|
|
3
|
-
|
|
4
|
-
import KeyboardCell from '../core/cell'
|
|
5
|
-
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
6
|
-
import { KeyboardWrapData } from '../types'
|
|
7
|
-
|
|
8
|
-
const KCAutoComplete: FC<AutoCompleteProps> = (props) => {
|
|
9
|
-
const { onFocus, onKeyDown, disabled, ...rest } = props
|
|
10
|
-
|
|
11
|
-
const cellRef = useRef<KeyboardCell>(null)
|
|
12
|
-
const autoCompleteRef = useRef<AutoCompleteRef>(null)
|
|
13
|
-
const { wrapData, cellKey } = useContextData()
|
|
14
|
-
|
|
15
|
-
const handleFocus = () => {
|
|
16
|
-
// eslint-disable-next-line
|
|
17
|
-
autoCompleteRef.current?.input?.focus()
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
autoCompleteRef.current?.triggerPopover(true)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
|
|
23
|
-
if (onFocus) {
|
|
24
|
-
onFocus(event)
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
event.target && event.target.select()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
31
|
-
scrollIntoViewFixedWidth(autoCompleteRef.current!.input!, fixedWidths)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
35
|
-
onKeyDown && onKeyDown(event)
|
|
36
|
-
if (isInputUnBoundary(event)) return
|
|
37
|
-
if (
|
|
38
|
-
event.key === 'ArrowUp' ||
|
|
39
|
-
event.key === 'ArrowRight' ||
|
|
40
|
-
event.key === 'ArrowDown' ||
|
|
41
|
-
event.key === 'ArrowLeft'
|
|
42
|
-
) {
|
|
43
|
-
// 需要阻止
|
|
44
|
-
// 如果下一个是 input,切换过去的时候光标会右移一位
|
|
45
|
-
event.preventDefault()
|
|
46
|
-
// eslint-disable-next-line
|
|
47
|
-
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
48
|
-
} else if (event.key === 'Tab') {
|
|
49
|
-
// 要阻止默认
|
|
50
|
-
// eslint-disable-next-line
|
|
51
|
-
cellRef.current?.apiDoTab()
|
|
52
|
-
} else if (event.key === 'Enter') {
|
|
53
|
-
// 要阻止默认
|
|
54
|
-
event.preventDefault()
|
|
55
|
-
// eslint-disable-next-line
|
|
56
|
-
cellRef.current?.apiDoEnter()
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return (
|
|
60
|
-
<KeyboardCell
|
|
61
|
-
ref={cellRef}
|
|
62
|
-
wrapData={wrapData}
|
|
63
|
-
cellKey={cellKey}
|
|
64
|
-
disabled={disabled}
|
|
65
|
-
onScroll={handleScroll}
|
|
66
|
-
onFocus={handleFocus}
|
|
67
|
-
>
|
|
68
|
-
<AutoComplete
|
|
69
|
-
ref={autoCompleteRef}
|
|
70
|
-
{...rest}
|
|
71
|
-
onFocus={handleInputFocus}
|
|
72
|
-
disabled={disabled}
|
|
73
|
-
onKeyDown={handleKeyDown}
|
|
74
|
-
/>
|
|
75
|
-
</KeyboardCell>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default KCAutoComplete
|
|
1
|
+
import React, { FC, useRef, FocusEvent, KeyboardEvent } from 'react'
|
|
2
|
+
import { AutoComplete, AutoCompleteRef, AutoCompleteProps } from '@gm-pc/react'
|
|
3
|
+
|
|
4
|
+
import KeyboardCell from '../core/cell'
|
|
5
|
+
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
6
|
+
import { KeyboardWrapData } from '../types'
|
|
7
|
+
|
|
8
|
+
const KCAutoComplete: FC<AutoCompleteProps> = (props) => {
|
|
9
|
+
const { onFocus, onKeyDown, disabled, ...rest } = props
|
|
10
|
+
|
|
11
|
+
const cellRef = useRef<KeyboardCell>(null)
|
|
12
|
+
const autoCompleteRef = useRef<AutoCompleteRef>(null)
|
|
13
|
+
const { wrapData, cellKey } = useContextData()
|
|
14
|
+
|
|
15
|
+
const handleFocus = () => {
|
|
16
|
+
// eslint-disable-next-line
|
|
17
|
+
autoCompleteRef.current?.input?.focus()
|
|
18
|
+
// eslint-disable-next-line
|
|
19
|
+
autoCompleteRef.current?.triggerPopover(true)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
|
|
23
|
+
if (onFocus) {
|
|
24
|
+
onFocus(event)
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
event.target && event.target.select()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
31
|
+
scrollIntoViewFixedWidth(autoCompleteRef.current!.input!, fixedWidths)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
35
|
+
onKeyDown && onKeyDown(event)
|
|
36
|
+
if (isInputUnBoundary(event)) return
|
|
37
|
+
if (
|
|
38
|
+
event.key === 'ArrowUp' ||
|
|
39
|
+
event.key === 'ArrowRight' ||
|
|
40
|
+
event.key === 'ArrowDown' ||
|
|
41
|
+
event.key === 'ArrowLeft'
|
|
42
|
+
) {
|
|
43
|
+
// 需要阻止
|
|
44
|
+
// 如果下一个是 input,切换过去的时候光标会右移一位
|
|
45
|
+
event.preventDefault()
|
|
46
|
+
// eslint-disable-next-line
|
|
47
|
+
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
48
|
+
} else if (event.key === 'Tab') {
|
|
49
|
+
// 要阻止默认
|
|
50
|
+
// eslint-disable-next-line
|
|
51
|
+
cellRef.current?.apiDoTab()
|
|
52
|
+
} else if (event.key === 'Enter') {
|
|
53
|
+
// 要阻止默认
|
|
54
|
+
event.preventDefault()
|
|
55
|
+
// eslint-disable-next-line
|
|
56
|
+
cellRef.current?.apiDoEnter()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return (
|
|
60
|
+
<KeyboardCell
|
|
61
|
+
ref={cellRef}
|
|
62
|
+
wrapData={wrapData}
|
|
63
|
+
cellKey={cellKey}
|
|
64
|
+
disabled={disabled}
|
|
65
|
+
onScroll={handleScroll}
|
|
66
|
+
onFocus={handleFocus}
|
|
67
|
+
>
|
|
68
|
+
<AutoComplete
|
|
69
|
+
ref={autoCompleteRef}
|
|
70
|
+
{...rest}
|
|
71
|
+
onFocus={handleInputFocus}
|
|
72
|
+
disabled={disabled}
|
|
73
|
+
onKeyDown={handleKeyDown}
|
|
74
|
+
/>
|
|
75
|
+
</KeyboardCell>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default KCAutoComplete
|
package/src/cell/cell.tsx
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import React, { FC } from 'react'
|
|
2
|
-
import { useContextData } from '../utils'
|
|
3
|
-
|
|
4
|
-
import KeyboardCell from '../core/cell'
|
|
5
|
-
import { KeyboardCellProps } from '../types'
|
|
6
|
-
|
|
7
|
-
const KC: FC<Pick<KeyboardCellProps, 'onFocus' | 'onScroll' | 'disabled'>> = ({
|
|
8
|
-
onFocus,
|
|
9
|
-
onScroll,
|
|
10
|
-
disabled,
|
|
11
|
-
children,
|
|
12
|
-
}) => {
|
|
13
|
-
const { wrapData, cellKey } = useContextData()
|
|
14
|
-
return (
|
|
15
|
-
<KeyboardCell
|
|
16
|
-
wrapData={wrapData}
|
|
17
|
-
cellKey={cellKey}
|
|
18
|
-
disabled={disabled}
|
|
19
|
-
onScroll={onScroll}
|
|
20
|
-
onFocus={onFocus}
|
|
21
|
-
>
|
|
22
|
-
{children}
|
|
23
|
-
</KeyboardCell>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default KC
|
|
1
|
+
import React, { FC } from 'react'
|
|
2
|
+
import { useContextData } from '../utils'
|
|
3
|
+
|
|
4
|
+
import KeyboardCell from '../core/cell'
|
|
5
|
+
import { KeyboardCellProps } from '../types'
|
|
6
|
+
|
|
7
|
+
const KC: FC<Pick<KeyboardCellProps, 'onFocus' | 'onScroll' | 'disabled'>> = ({
|
|
8
|
+
onFocus,
|
|
9
|
+
onScroll,
|
|
10
|
+
disabled,
|
|
11
|
+
children,
|
|
12
|
+
}) => {
|
|
13
|
+
const { wrapData, cellKey } = useContextData()
|
|
14
|
+
return (
|
|
15
|
+
<KeyboardCell
|
|
16
|
+
wrapData={wrapData}
|
|
17
|
+
cellKey={cellKey}
|
|
18
|
+
disabled={disabled}
|
|
19
|
+
onScroll={onScroll}
|
|
20
|
+
onFocus={onFocus}
|
|
21
|
+
>
|
|
22
|
+
{children}
|
|
23
|
+
</KeyboardCell>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default KC
|
package/src/cell/date_picker.tsx
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import React, { FC, useRef, KeyboardEvent } from 'react'
|
|
2
|
-
import { DatePicker, DatePickerProps } from '@gm-pc/react'
|
|
3
|
-
import { findDOMNode } from 'react-dom'
|
|
4
|
-
|
|
5
|
-
import KeyboardCell from '../core/cell'
|
|
6
|
-
import { scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
7
|
-
import { KeyboardWrapData } from '../types'
|
|
8
|
-
|
|
9
|
-
const KCDatePicker: FC<DatePickerProps> = ({ disabled, onKeyDown, ...rest }) => {
|
|
10
|
-
const cellRef = useRef<KeyboardCell>(null)
|
|
11
|
-
const targetRef = useRef<DatePicker>(null)
|
|
12
|
-
const { wrapData, cellKey } = useContextData()
|
|
13
|
-
|
|
14
|
-
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
15
|
-
scrollIntoViewFixedWidth(findDOMNode(targetRef.current) as HTMLElement, fixedWidths)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const handleFocus = () => {
|
|
19
|
-
if (targetRef.current) {
|
|
20
|
-
targetRef.current.apiDoFocus()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const handleKeyDown = (event: KeyboardEvent) => {
|
|
25
|
-
onKeyDown && onKeyDown(event)
|
|
26
|
-
if (
|
|
27
|
-
event.key === 'ArrowUp' ||
|
|
28
|
-
event.key === 'ArrowDown' ||
|
|
29
|
-
event.key === 'ArrowLeft' ||
|
|
30
|
-
event.key === 'ArrowRight'
|
|
31
|
-
) {
|
|
32
|
-
// 需要阻止。
|
|
33
|
-
// 如果下一个是input,切过去的时候光标会右移一位是 keydown
|
|
34
|
-
event.preventDefault()
|
|
35
|
-
// eslint-disable-next-line
|
|
36
|
-
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
37
|
-
} else if (event.key === 'Tab') {
|
|
38
|
-
// 要阻止默认的
|
|
39
|
-
event.preventDefault()
|
|
40
|
-
// eslint-disable-next-line
|
|
41
|
-
cellRef.current?.apiDoTab()
|
|
42
|
-
} else if (event.key === 'Enter') {
|
|
43
|
-
// 要阻止默认的
|
|
44
|
-
event.preventDefault()
|
|
45
|
-
// enter 要选择
|
|
46
|
-
// eslint-disable-next-line
|
|
47
|
-
targetRef.current?.apiDoSelectWillActive()
|
|
48
|
-
// eslint-disable-next-line
|
|
49
|
-
cellRef.current?.apiDoEnter()
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<KeyboardCell
|
|
55
|
-
disabled={disabled}
|
|
56
|
-
ref={cellRef}
|
|
57
|
-
wrapData={wrapData}
|
|
58
|
-
cellKey={cellKey}
|
|
59
|
-
onFocus={handleFocus}
|
|
60
|
-
onScroll={handleScroll}
|
|
61
|
-
>
|
|
62
|
-
<DatePicker
|
|
63
|
-
disabled={disabled}
|
|
64
|
-
{...rest}
|
|
65
|
-
popoverType='realFocus'
|
|
66
|
-
onKeyDown={handleKeyDown}
|
|
67
|
-
ref={targetRef}
|
|
68
|
-
/>
|
|
69
|
-
</KeyboardCell>
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export default KCDatePicker
|
|
1
|
+
import React, { FC, useRef, KeyboardEvent } from 'react'
|
|
2
|
+
import { DatePicker, DatePickerProps } from '@gm-pc/react'
|
|
3
|
+
import { findDOMNode } from 'react-dom'
|
|
4
|
+
|
|
5
|
+
import KeyboardCell from '../core/cell'
|
|
6
|
+
import { scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
7
|
+
import { KeyboardWrapData } from '../types'
|
|
8
|
+
|
|
9
|
+
const KCDatePicker: FC<DatePickerProps> = ({ disabled, onKeyDown, ...rest }) => {
|
|
10
|
+
const cellRef = useRef<KeyboardCell>(null)
|
|
11
|
+
const targetRef = useRef<DatePicker>(null)
|
|
12
|
+
const { wrapData, cellKey } = useContextData()
|
|
13
|
+
|
|
14
|
+
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
15
|
+
scrollIntoViewFixedWidth(findDOMNode(targetRef.current) as HTMLElement, fixedWidths)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const handleFocus = () => {
|
|
19
|
+
if (targetRef.current) {
|
|
20
|
+
targetRef.current.apiDoFocus()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
25
|
+
onKeyDown && onKeyDown(event)
|
|
26
|
+
if (
|
|
27
|
+
event.key === 'ArrowUp' ||
|
|
28
|
+
event.key === 'ArrowDown' ||
|
|
29
|
+
event.key === 'ArrowLeft' ||
|
|
30
|
+
event.key === 'ArrowRight'
|
|
31
|
+
) {
|
|
32
|
+
// 需要阻止。
|
|
33
|
+
// 如果下一个是input,切过去的时候光标会右移一位是 keydown
|
|
34
|
+
event.preventDefault()
|
|
35
|
+
// eslint-disable-next-line
|
|
36
|
+
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
37
|
+
} else if (event.key === 'Tab') {
|
|
38
|
+
// 要阻止默认的
|
|
39
|
+
event.preventDefault()
|
|
40
|
+
// eslint-disable-next-line
|
|
41
|
+
cellRef.current?.apiDoTab()
|
|
42
|
+
} else if (event.key === 'Enter') {
|
|
43
|
+
// 要阻止默认的
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
// enter 要选择
|
|
46
|
+
// eslint-disable-next-line
|
|
47
|
+
targetRef.current?.apiDoSelectWillActive()
|
|
48
|
+
// eslint-disable-next-line
|
|
49
|
+
cellRef.current?.apiDoEnter()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<KeyboardCell
|
|
55
|
+
disabled={disabled}
|
|
56
|
+
ref={cellRef}
|
|
57
|
+
wrapData={wrapData}
|
|
58
|
+
cellKey={cellKey}
|
|
59
|
+
onFocus={handleFocus}
|
|
60
|
+
onScroll={handleScroll}
|
|
61
|
+
>
|
|
62
|
+
<DatePicker
|
|
63
|
+
disabled={disabled}
|
|
64
|
+
{...rest}
|
|
65
|
+
popoverType='realFocus'
|
|
66
|
+
onKeyDown={handleKeyDown}
|
|
67
|
+
ref={targetRef}
|
|
68
|
+
/>
|
|
69
|
+
</KeyboardCell>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default KCDatePicker
|
package/src/cell/input.tsx
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import React, { FC, useRef, FocusEvent, KeyboardEvent } from 'react'
|
|
2
|
-
import { Input, InputProps } from '@gm-pc/react'
|
|
3
|
-
|
|
4
|
-
import KeyboardCell from '../core/cell'
|
|
5
|
-
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
6
|
-
import { KeyboardWrapData } from '../types'
|
|
7
|
-
|
|
8
|
-
const KCInput: FC<InputProps> = ({ disabled, onKeyDown, onFocus, ...rest }) => {
|
|
9
|
-
const cellRef = useRef<KeyboardCell>(null)
|
|
10
|
-
const targetRef = useRef<HTMLInputElement>(null)
|
|
11
|
-
const { wrapData, cellKey } = useContextData()
|
|
12
|
-
|
|
13
|
-
const handleFocus = () => {
|
|
14
|
-
// eslint-disable-next-line
|
|
15
|
-
targetRef.current?.focus()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
|
|
19
|
-
if (onFocus) {
|
|
20
|
-
onFocus(event)
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
event.target && event.target.select()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
27
|
-
scrollIntoViewFixedWidth(targetRef.current!, fixedWidths)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
31
|
-
onKeyDown && onKeyDown(event)
|
|
32
|
-
if (isInputUnBoundary(event)) return
|
|
33
|
-
if (
|
|
34
|
-
event.key === 'ArrowUp' ||
|
|
35
|
-
event.key === 'ArrowRight' ||
|
|
36
|
-
event.key === 'ArrowDown' ||
|
|
37
|
-
event.key === 'ArrowLeft'
|
|
38
|
-
) {
|
|
39
|
-
// 需要阻止
|
|
40
|
-
// 如果下一个是 input,切换过去的时候光标会右移一位
|
|
41
|
-
event.preventDefault()
|
|
42
|
-
// eslint-disable-next-line
|
|
43
|
-
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
44
|
-
} else if (event.key === 'Tab') {
|
|
45
|
-
// 要阻止默认
|
|
46
|
-
// eslint-disable-next-line
|
|
47
|
-
cellRef.current?.apiDoTab()
|
|
48
|
-
} else if (event.key === 'Enter') {
|
|
49
|
-
// 要阻止默认
|
|
50
|
-
event.preventDefault()
|
|
51
|
-
// eslint-disable-next-line
|
|
52
|
-
cellRef.current?.apiDoEnter()
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return (
|
|
56
|
-
<KeyboardCell
|
|
57
|
-
ref={cellRef}
|
|
58
|
-
wrapData={wrapData}
|
|
59
|
-
cellKey={cellKey}
|
|
60
|
-
disabled={disabled}
|
|
61
|
-
onScroll={handleScroll}
|
|
62
|
-
onFocus={handleFocus}
|
|
63
|
-
>
|
|
64
|
-
<Input
|
|
65
|
-
ref={targetRef}
|
|
66
|
-
{...rest}
|
|
67
|
-
onFocus={handleInputFocus}
|
|
68
|
-
disabled={disabled}
|
|
69
|
-
onKeyDown={handleKeyDown}
|
|
70
|
-
/>
|
|
71
|
-
</KeyboardCell>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export default KCInput
|
|
1
|
+
import React, { FC, useRef, FocusEvent, KeyboardEvent } from 'react'
|
|
2
|
+
import { Input, InputProps } from '@gm-pc/react'
|
|
3
|
+
|
|
4
|
+
import KeyboardCell from '../core/cell'
|
|
5
|
+
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
6
|
+
import { KeyboardWrapData } from '../types'
|
|
7
|
+
|
|
8
|
+
const KCInput: FC<InputProps> = ({ disabled, onKeyDown, onFocus, ...rest }) => {
|
|
9
|
+
const cellRef = useRef<KeyboardCell>(null)
|
|
10
|
+
const targetRef = useRef<HTMLInputElement>(null)
|
|
11
|
+
const { wrapData, cellKey } = useContextData()
|
|
12
|
+
|
|
13
|
+
const handleFocus = () => {
|
|
14
|
+
// eslint-disable-next-line
|
|
15
|
+
targetRef.current?.focus()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
|
|
19
|
+
if (onFocus) {
|
|
20
|
+
onFocus(event)
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
event.target && event.target.select()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
27
|
+
scrollIntoViewFixedWidth(targetRef.current!, fixedWidths)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
31
|
+
onKeyDown && onKeyDown(event)
|
|
32
|
+
if (isInputUnBoundary(event)) return
|
|
33
|
+
if (
|
|
34
|
+
event.key === 'ArrowUp' ||
|
|
35
|
+
event.key === 'ArrowRight' ||
|
|
36
|
+
event.key === 'ArrowDown' ||
|
|
37
|
+
event.key === 'ArrowLeft'
|
|
38
|
+
) {
|
|
39
|
+
// 需要阻止
|
|
40
|
+
// 如果下一个是 input,切换过去的时候光标会右移一位
|
|
41
|
+
event.preventDefault()
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
44
|
+
} else if (event.key === 'Tab') {
|
|
45
|
+
// 要阻止默认
|
|
46
|
+
// eslint-disable-next-line
|
|
47
|
+
cellRef.current?.apiDoTab()
|
|
48
|
+
} else if (event.key === 'Enter') {
|
|
49
|
+
// 要阻止默认
|
|
50
|
+
event.preventDefault()
|
|
51
|
+
// eslint-disable-next-line
|
|
52
|
+
cellRef.current?.apiDoEnter()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return (
|
|
56
|
+
<KeyboardCell
|
|
57
|
+
ref={cellRef}
|
|
58
|
+
wrapData={wrapData}
|
|
59
|
+
cellKey={cellKey}
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
onScroll={handleScroll}
|
|
62
|
+
onFocus={handleFocus}
|
|
63
|
+
>
|
|
64
|
+
<Input
|
|
65
|
+
ref={targetRef}
|
|
66
|
+
{...rest}
|
|
67
|
+
onFocus={handleInputFocus}
|
|
68
|
+
disabled={disabled}
|
|
69
|
+
onKeyDown={handleKeyDown}
|
|
70
|
+
/>
|
|
71
|
+
</KeyboardCell>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default KCInput
|