@gm-pc/keyboard 1.16.0 → 1.17.0-beta.10
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 -0
- package/src/cell/input_number.tsx +1 -1
- package/src/cell/more_select.tsx +18 -4
- package/src/index.ts +1 -0
- package/src/types.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-pc/keyboard",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0-beta.10",
|
|
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.
|
|
31
|
-
"@gm-pc/table-x": "^1.
|
|
30
|
+
"@gm-pc/react": "^1.17.0-beta.10",
|
|
31
|
+
"@gm-pc/table-x": "^1.17.0-beta.10",
|
|
32
32
|
"classnames": "^2.2.5",
|
|
33
33
|
"lodash": "^4.17.19"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "b7017b352488f540d5108043888c7bea8d2c499a"
|
|
36
36
|
}
|
|
@@ -0,0 +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
|
|
@@ -31,7 +31,7 @@ const KCInputNumber: ForwardRefRenderFunction<RefFunctionProps, InputNumberProps
|
|
|
31
31
|
|
|
32
32
|
const handleFocus = () => {
|
|
33
33
|
// eslint-disable-next-line
|
|
34
|
-
targetRef.current?.
|
|
34
|
+
targetRef.current?.apiDoFocus()
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
|
package/src/cell/more_select.tsx
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import React, { useRef, KeyboardEvent } from 'react'
|
|
1
|
+
import React, { useRef, KeyboardEvent, forwardRef, useImperativeHandle } from 'react'
|
|
2
2
|
import { MoreSelect, MoreSelectProps } from '@gm-pc/react'
|
|
3
3
|
import { findDOMNode } from 'react-dom'
|
|
4
4
|
|
|
5
5
|
import KeyboardCell from '../core/cell'
|
|
6
6
|
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
7
|
-
import { KeyboardWrapData } from '../types'
|
|
7
|
+
import { KeyboardWrapData, MoreSelectRef } from '../types'
|
|
8
8
|
|
|
9
|
-
function KCMoreSelect<V>(
|
|
9
|
+
function KCMoreSelect<V>(
|
|
10
|
+
{ disabled, onKeyDown, ...rest }: MoreSelectProps<V>,
|
|
11
|
+
ref: React.ForwardedRef<MoreSelectRef>
|
|
12
|
+
) {
|
|
10
13
|
const cellRef = useRef<KeyboardCell>(null)
|
|
11
14
|
const targetRef = useRef<MoreSelect>(null)
|
|
12
15
|
const { wrapData, cellKey } = useContextData()
|
|
13
16
|
|
|
17
|
+
useImperativeHandle(ref, () => {
|
|
18
|
+
return {
|
|
19
|
+
handleInitSearch,
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
14
23
|
const handleFocus = () => {
|
|
15
24
|
// eslint-disable-next-line
|
|
16
25
|
targetRef.current?.apiDoFocus()
|
|
@@ -45,6 +54,11 @@ function KCMoreSelect<V>({ disabled, onKeyDown, ...rest }: MoreSelectProps<V>) {
|
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
56
|
|
|
57
|
+
const handleInitSearch = (q?: string) => {
|
|
58
|
+
// eslint-disable-next-line no-unused-expressions
|
|
59
|
+
targetRef.current?._handleInitSearch(q)
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
return (
|
|
49
63
|
<KeyboardCell
|
|
50
64
|
ref={cellRef}
|
|
@@ -66,4 +80,4 @@ function KCMoreSelect<V>({ disabled, onKeyDown, ...rest }: MoreSelectProps<V>) {
|
|
|
66
80
|
)
|
|
67
81
|
}
|
|
68
82
|
|
|
69
|
-
export default KCMoreSelect
|
|
83
|
+
export default forwardRef(KCMoreSelect)
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export const KeyboardUtil = { isInputUnBoundary, scrollIntoViewFixedWidth, doFoc
|
|
|
5
5
|
export { default as keyboardTableXHOC } from './hoc/keyboard_table_x'
|
|
6
6
|
|
|
7
7
|
export { default as KC } from './cell/cell'
|
|
8
|
+
export { default as KCAutoComplete } from './cell/auto_complete'
|
|
8
9
|
export { default as KCInput } from './cell/input'
|
|
9
10
|
export { default as KCMoreSelect } from './cell/more_select'
|
|
10
11
|
export { default as KCInputNumber } from './cell/input_number'
|
package/src/types.ts
CHANGED
|
@@ -65,6 +65,11 @@ interface WrapProps {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
type MoreSelectRef = {
|
|
69
|
+
/** 默认搜索 */
|
|
70
|
+
handleInitSearch: (q?: string) => void
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
export type {
|
|
69
74
|
KeyboardCellProps,
|
|
70
75
|
WrapProps,
|
|
@@ -73,4 +78,5 @@ export type {
|
|
|
73
78
|
KeyboardCustomEvent,
|
|
74
79
|
KeyboardDirection,
|
|
75
80
|
KeyboardWrapData,
|
|
81
|
+
MoreSelectRef,
|
|
76
82
|
}
|