@gm-pc/keyboard 1.17.0-beta.0 → 1.17.0-beta.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-pc/keyboard",
3
- "version": "1.17.0-beta.0",
3
+ "version": "1.17.0-beta.1",
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.17.0-beta.0",
31
- "@gm-pc/table-x": "^1.17.0-beta.0",
30
+ "@gm-pc/react": "^1.17.0-beta.1",
31
+ "@gm-pc/table-x": "^1.17.0-beta.1",
32
32
  "classnames": "^2.2.5",
33
33
  "lodash": "^4.17.19"
34
34
  },
35
- "gitHead": "4ded82c728d9153ce0f837ad39777ac461a57d1f"
35
+ "gitHead": "1781bbccfc4d5ebcddad1572fcec3f855d19b9f5"
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
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'