@gm-pc/keyboard 1.27.0 → 1.27.1-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
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useRef,
|
|
3
|
-
FocusEvent,
|
|
4
|
-
KeyboardEvent,
|
|
5
|
-
useImperativeHandle,
|
|
6
|
-
forwardRef,
|
|
7
|
-
ForwardRefRenderFunction,
|
|
8
|
-
} from 'react'
|
|
9
|
-
import { InputNumber, InputNumberProps } from '@gm-pc/react'
|
|
10
|
-
import { findDOMNode } from 'react-dom'
|
|
11
|
-
|
|
12
|
-
import KeyboardCell from '../core/cell'
|
|
13
|
-
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
14
|
-
import { KeyboardWrapData } from '../types'
|
|
15
|
-
|
|
16
|
-
interface RefFunctionProps {
|
|
17
|
-
focus(): void
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const KCInputNumber: ForwardRefRenderFunction<RefFunctionProps, InputNumberProps> = (
|
|
21
|
-
{ disabled, onKeyDown, onFocus, ...rest },
|
|
22
|
-
ref
|
|
23
|
-
) => {
|
|
24
|
-
const cellRef = useRef<KeyboardCell>(null)
|
|
25
|
-
const targetRef = useRef<InputNumber>(null)
|
|
26
|
-
const { cellKey, wrapData } = useContextData()
|
|
27
|
-
|
|
28
|
-
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
29
|
-
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const handleFocus = () => {
|
|
33
|
-
// eslint-disable-next-line
|
|
34
|
-
targetRef.current?.apiDoFocus()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
|
|
38
|
-
if (onFocus) {
|
|
39
|
-
onFocus(event)
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
event.target && event.target.select()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
46
|
-
onKeyDown && onKeyDown(event)
|
|
47
|
-
if (isInputUnBoundary(event)) return
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
event.key === 'ArrowUp' ||
|
|
51
|
-
event.key === 'ArrowRight' ||
|
|
52
|
-
event.key === 'ArrowDown' ||
|
|
53
|
-
event.key === 'ArrowLeft'
|
|
54
|
-
) {
|
|
55
|
-
event.preventDefault()
|
|
56
|
-
// eslint-disable-next-line
|
|
57
|
-
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
58
|
-
} else if (event.key === 'Tab') {
|
|
59
|
-
event.preventDefault()
|
|
60
|
-
// eslint-disable-next-line
|
|
61
|
-
cellRef.current?.apiDoTab()
|
|
62
|
-
} else if (event.key === 'Enter') {
|
|
63
|
-
event.preventDefault()
|
|
64
|
-
// eslint-disable-next-line
|
|
65
|
-
cellRef.current?.apiDoEnter()
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
useImperativeHandle(ref, () => ({
|
|
69
|
-
focus: handleFocus,
|
|
70
|
-
}))
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<KeyboardCell
|
|
74
|
-
ref={cellRef}
|
|
75
|
-
wrapData={wrapData}
|
|
76
|
-
cellKey={cellKey}
|
|
77
|
-
onFocus={handleFocus}
|
|
78
|
-
disabled={disabled}
|
|
79
|
-
onScroll={handleScroll}
|
|
80
|
-
>
|
|
81
|
-
<InputNumber
|
|
82
|
-
{...rest}
|
|
83
|
-
onFocus={handleInputFocus}
|
|
84
|
-
ref={targetRef}
|
|
85
|
-
disabled={disabled}
|
|
86
|
-
onKeyDown={handleKeyDown}
|
|
87
|
-
/>
|
|
88
|
-
</KeyboardCell>
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export default forwardRef(KCInputNumber)
|
|
1
|
+
import React, {
|
|
2
|
+
useRef,
|
|
3
|
+
FocusEvent,
|
|
4
|
+
KeyboardEvent,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
forwardRef,
|
|
7
|
+
ForwardRefRenderFunction,
|
|
8
|
+
} from 'react'
|
|
9
|
+
import { InputNumber, InputNumberProps } from '@gm-pc/react'
|
|
10
|
+
import { findDOMNode } from 'react-dom'
|
|
11
|
+
|
|
12
|
+
import KeyboardCell from '../core/cell'
|
|
13
|
+
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
14
|
+
import { KeyboardWrapData } from '../types'
|
|
15
|
+
|
|
16
|
+
interface RefFunctionProps {
|
|
17
|
+
focus(): void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const KCInputNumber: ForwardRefRenderFunction<RefFunctionProps, InputNumberProps> = (
|
|
21
|
+
{ disabled, onKeyDown, onFocus, ...rest },
|
|
22
|
+
ref
|
|
23
|
+
) => {
|
|
24
|
+
const cellRef = useRef<KeyboardCell>(null)
|
|
25
|
+
const targetRef = useRef<InputNumber>(null)
|
|
26
|
+
const { cellKey, wrapData } = useContextData()
|
|
27
|
+
|
|
28
|
+
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
29
|
+
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const handleFocus = () => {
|
|
33
|
+
// eslint-disable-next-line
|
|
34
|
+
targetRef.current?.apiDoFocus()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const handleInputFocus = (event: FocusEvent<HTMLInputElement>) => {
|
|
38
|
+
if (onFocus) {
|
|
39
|
+
onFocus(event)
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
event.target && event.target.select()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
46
|
+
onKeyDown && onKeyDown(event)
|
|
47
|
+
if (isInputUnBoundary(event)) return
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
event.key === 'ArrowUp' ||
|
|
51
|
+
event.key === 'ArrowRight' ||
|
|
52
|
+
event.key === 'ArrowDown' ||
|
|
53
|
+
event.key === 'ArrowLeft'
|
|
54
|
+
) {
|
|
55
|
+
event.preventDefault()
|
|
56
|
+
// eslint-disable-next-line
|
|
57
|
+
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
58
|
+
} else if (event.key === 'Tab') {
|
|
59
|
+
event.preventDefault()
|
|
60
|
+
// eslint-disable-next-line
|
|
61
|
+
cellRef.current?.apiDoTab()
|
|
62
|
+
} else if (event.key === 'Enter') {
|
|
63
|
+
event.preventDefault()
|
|
64
|
+
// eslint-disable-next-line
|
|
65
|
+
cellRef.current?.apiDoEnter()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
useImperativeHandle(ref, () => ({
|
|
69
|
+
focus: handleFocus,
|
|
70
|
+
}))
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<KeyboardCell
|
|
74
|
+
ref={cellRef}
|
|
75
|
+
wrapData={wrapData}
|
|
76
|
+
cellKey={cellKey}
|
|
77
|
+
onFocus={handleFocus}
|
|
78
|
+
disabled={disabled}
|
|
79
|
+
onScroll={handleScroll}
|
|
80
|
+
>
|
|
81
|
+
<InputNumber
|
|
82
|
+
{...rest}
|
|
83
|
+
onFocus={handleInputFocus}
|
|
84
|
+
ref={targetRef}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
onKeyDown={handleKeyDown}
|
|
87
|
+
/>
|
|
88
|
+
</KeyboardCell>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default forwardRef(KCInputNumber)
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import React, { useRef, KeyboardEvent } from 'react'
|
|
2
|
-
import { LevelSelect, LevelSelectProps } from '@gm-pc/react'
|
|
3
|
-
import { findDOMNode } from 'react-dom'
|
|
4
|
-
|
|
5
|
-
import KeyboardCell from '../core/cell'
|
|
6
|
-
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
7
|
-
import { KeyboardWrapData } from '../types'
|
|
8
|
-
|
|
9
|
-
function KCLevelSelect<V = any>({ disabled, onKeyDown, ...rest }: LevelSelectProps<V>) {
|
|
10
|
-
const cellRef = useRef<KeyboardCell>(null)
|
|
11
|
-
const targetRef = useRef<LevelSelect>(null)
|
|
12
|
-
const { wrapData, cellKey } = useContextData()
|
|
13
|
-
|
|
14
|
-
const handleFocus = () => {
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
targetRef.current?.apiDoFocus()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
20
|
-
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
|
24
|
-
onKeyDown && onKeyDown(event)
|
|
25
|
-
|
|
26
|
-
if (isInputUnBoundary(event)) return
|
|
27
|
-
if (
|
|
28
|
-
event.key === 'ArrowLeft' ||
|
|
29
|
-
event.key === 'ArrowRight' ||
|
|
30
|
-
event.key === 'ArrowUp' ||
|
|
31
|
-
event.key === 'ArrowDown'
|
|
32
|
-
) {
|
|
33
|
-
event.preventDefault()
|
|
34
|
-
// eslint-disable-next-line
|
|
35
|
-
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
36
|
-
} else if (event.key === 'Tab') {
|
|
37
|
-
event.preventDefault()
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
cellRef.current?.apiDoTab()
|
|
40
|
-
} else if (event.key === 'Enter') {
|
|
41
|
-
event.preventDefault()
|
|
42
|
-
// enter 要选择
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
targetRef.current.apiDoSelectWillActive()
|
|
45
|
-
// eslint-disable-next-line
|
|
46
|
-
cellRef.current?.apiDoEnter()
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<KeyboardCell
|
|
52
|
-
disabled={disabled}
|
|
53
|
-
ref={cellRef}
|
|
54
|
-
wrapData={wrapData}
|
|
55
|
-
cellKey={cellKey}
|
|
56
|
-
onFocus={handleFocus}
|
|
57
|
-
onScroll={handleScroll}
|
|
58
|
-
>
|
|
59
|
-
<LevelSelect
|
|
60
|
-
{...rest}
|
|
61
|
-
ref={targetRef}
|
|
62
|
-
popoverType='realFocus'
|
|
63
|
-
disabled={disabled}
|
|
64
|
-
onKeyDown={handleKeyDown}
|
|
65
|
-
/>
|
|
66
|
-
</KeyboardCell>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default KCLevelSelect
|
|
1
|
+
import React, { useRef, KeyboardEvent } from 'react'
|
|
2
|
+
import { LevelSelect, LevelSelectProps } from '@gm-pc/react'
|
|
3
|
+
import { findDOMNode } from 'react-dom'
|
|
4
|
+
|
|
5
|
+
import KeyboardCell from '../core/cell'
|
|
6
|
+
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
7
|
+
import { KeyboardWrapData } from '../types'
|
|
8
|
+
|
|
9
|
+
function KCLevelSelect<V = any>({ disabled, onKeyDown, ...rest }: LevelSelectProps<V>) {
|
|
10
|
+
const cellRef = useRef<KeyboardCell>(null)
|
|
11
|
+
const targetRef = useRef<LevelSelect>(null)
|
|
12
|
+
const { wrapData, cellKey } = useContextData()
|
|
13
|
+
|
|
14
|
+
const handleFocus = () => {
|
|
15
|
+
// eslint-disable-next-line
|
|
16
|
+
targetRef.current?.apiDoFocus()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
20
|
+
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
|
24
|
+
onKeyDown && onKeyDown(event)
|
|
25
|
+
|
|
26
|
+
if (isInputUnBoundary(event)) return
|
|
27
|
+
if (
|
|
28
|
+
event.key === 'ArrowLeft' ||
|
|
29
|
+
event.key === 'ArrowRight' ||
|
|
30
|
+
event.key === 'ArrowUp' ||
|
|
31
|
+
event.key === 'ArrowDown'
|
|
32
|
+
) {
|
|
33
|
+
event.preventDefault()
|
|
34
|
+
// eslint-disable-next-line
|
|
35
|
+
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
36
|
+
} else if (event.key === 'Tab') {
|
|
37
|
+
event.preventDefault()
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
cellRef.current?.apiDoTab()
|
|
40
|
+
} else if (event.key === 'Enter') {
|
|
41
|
+
event.preventDefault()
|
|
42
|
+
// enter 要选择
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
targetRef.current.apiDoSelectWillActive()
|
|
45
|
+
// eslint-disable-next-line
|
|
46
|
+
cellRef.current?.apiDoEnter()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<KeyboardCell
|
|
52
|
+
disabled={disabled}
|
|
53
|
+
ref={cellRef}
|
|
54
|
+
wrapData={wrapData}
|
|
55
|
+
cellKey={cellKey}
|
|
56
|
+
onFocus={handleFocus}
|
|
57
|
+
onScroll={handleScroll}
|
|
58
|
+
>
|
|
59
|
+
<LevelSelect
|
|
60
|
+
{...rest}
|
|
61
|
+
ref={targetRef}
|
|
62
|
+
popoverType='realFocus'
|
|
63
|
+
disabled={disabled}
|
|
64
|
+
onKeyDown={handleKeyDown}
|
|
65
|
+
/>
|
|
66
|
+
</KeyboardCell>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default KCLevelSelect
|
package/src/cell/more_select.tsx
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import React, { useRef, KeyboardEvent, forwardRef, useImperativeHandle } from 'react'
|
|
2
|
-
import { MoreSelect, MoreSelectProps } from '@gm-pc/react'
|
|
3
|
-
import { findDOMNode } from 'react-dom'
|
|
4
|
-
|
|
5
|
-
import KeyboardCell from '../core/cell'
|
|
6
|
-
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
7
|
-
import { KeyboardWrapData, MoreSelectRef } from '../types'
|
|
8
|
-
|
|
9
|
-
function KCMoreSelect<V>(
|
|
10
|
-
{ disabled, onKeyDown, ...rest }: MoreSelectProps<V>,
|
|
11
|
-
ref: React.ForwardedRef<MoreSelectRef>
|
|
12
|
-
) {
|
|
13
|
-
const cellRef = useRef<KeyboardCell>(null)
|
|
14
|
-
const targetRef = useRef<MoreSelect>(null)
|
|
15
|
-
const { wrapData, cellKey } = useContextData()
|
|
16
|
-
|
|
17
|
-
useImperativeHandle(ref, () => {
|
|
18
|
-
return {
|
|
19
|
-
handleInitSearch,
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const handleFocus = () => {
|
|
24
|
-
// eslint-disable-next-line
|
|
25
|
-
targetRef.current?.apiDoFocus()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
29
|
-
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
|
33
|
-
onKeyDown && onKeyDown(event)
|
|
34
|
-
if (isInputUnBoundary(event)) return
|
|
35
|
-
if (
|
|
36
|
-
event.key === 'ArrowUp' ||
|
|
37
|
-
event.key === 'ArrowLeft' ||
|
|
38
|
-
event.key === 'ArrowRight' ||
|
|
39
|
-
event.key === 'ArrowDown'
|
|
40
|
-
) {
|
|
41
|
-
event.preventDefault()
|
|
42
|
-
// eslint-disable-next-line
|
|
43
|
-
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
44
|
-
} else if (event.key === 'Tab') {
|
|
45
|
-
event.preventDefault()
|
|
46
|
-
// eslint-disable-next-line
|
|
47
|
-
cellRef.current?.apiDoTab()
|
|
48
|
-
} else if (event.key === 'Enter') {
|
|
49
|
-
event.preventDefault()
|
|
50
|
-
// eslint-disable-next-line
|
|
51
|
-
targetRef.current?.apiDoSelectWillActive()
|
|
52
|
-
// eslint-disable-next-line
|
|
53
|
-
cellRef.current?.apiDoEnter()
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const handleInitSearch = (q?: string) => {
|
|
58
|
-
// eslint-disable-next-line no-unused-expressions
|
|
59
|
-
targetRef.current?._handleInitSearch(q)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<KeyboardCell
|
|
64
|
-
ref={cellRef}
|
|
65
|
-
disabled={disabled}
|
|
66
|
-
wrapData={wrapData}
|
|
67
|
-
cellKey={cellKey}
|
|
68
|
-
onFocus={handleFocus}
|
|
69
|
-
onScroll={handleScroll}
|
|
70
|
-
>
|
|
71
|
-
<MoreSelect<V>
|
|
72
|
-
{...rest}
|
|
73
|
-
disabled={disabled}
|
|
74
|
-
ref={targetRef}
|
|
75
|
-
popoverType='realFocus'
|
|
76
|
-
onKeyDown={handleKeyDown}
|
|
77
|
-
isKeyboard
|
|
78
|
-
/>
|
|
79
|
-
</KeyboardCell>
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export default forwardRef(KCMoreSelect)
|
|
1
|
+
import React, { useRef, KeyboardEvent, forwardRef, useImperativeHandle } from 'react'
|
|
2
|
+
import { MoreSelect, MoreSelectProps } from '@gm-pc/react'
|
|
3
|
+
import { findDOMNode } from 'react-dom'
|
|
4
|
+
|
|
5
|
+
import KeyboardCell from '../core/cell'
|
|
6
|
+
import { isInputUnBoundary, scrollIntoViewFixedWidth, useContextData } from '../utils'
|
|
7
|
+
import { KeyboardWrapData, MoreSelectRef } from '../types'
|
|
8
|
+
|
|
9
|
+
function KCMoreSelect<V>(
|
|
10
|
+
{ disabled, onKeyDown, ...rest }: MoreSelectProps<V>,
|
|
11
|
+
ref: React.ForwardedRef<MoreSelectRef>
|
|
12
|
+
) {
|
|
13
|
+
const cellRef = useRef<KeyboardCell>(null)
|
|
14
|
+
const targetRef = useRef<MoreSelect>(null)
|
|
15
|
+
const { wrapData, cellKey } = useContextData()
|
|
16
|
+
|
|
17
|
+
useImperativeHandle(ref, () => {
|
|
18
|
+
return {
|
|
19
|
+
handleInitSearch,
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const handleFocus = () => {
|
|
24
|
+
// eslint-disable-next-line
|
|
25
|
+
targetRef.current?.apiDoFocus()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
29
|
+
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
|
33
|
+
onKeyDown && onKeyDown(event)
|
|
34
|
+
if (isInputUnBoundary(event)) return
|
|
35
|
+
if (
|
|
36
|
+
event.key === 'ArrowUp' ||
|
|
37
|
+
event.key === 'ArrowLeft' ||
|
|
38
|
+
event.key === 'ArrowRight' ||
|
|
39
|
+
event.key === 'ArrowDown'
|
|
40
|
+
) {
|
|
41
|
+
event.preventDefault()
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
44
|
+
} else if (event.key === 'Tab') {
|
|
45
|
+
event.preventDefault()
|
|
46
|
+
// eslint-disable-next-line
|
|
47
|
+
cellRef.current?.apiDoTab()
|
|
48
|
+
} else if (event.key === 'Enter') {
|
|
49
|
+
event.preventDefault()
|
|
50
|
+
// eslint-disable-next-line
|
|
51
|
+
targetRef.current?.apiDoSelectWillActive()
|
|
52
|
+
// eslint-disable-next-line
|
|
53
|
+
cellRef.current?.apiDoEnter()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const handleInitSearch = (q?: string) => {
|
|
58
|
+
// eslint-disable-next-line no-unused-expressions
|
|
59
|
+
targetRef.current?._handleInitSearch(q)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<KeyboardCell
|
|
64
|
+
ref={cellRef}
|
|
65
|
+
disabled={disabled}
|
|
66
|
+
wrapData={wrapData}
|
|
67
|
+
cellKey={cellKey}
|
|
68
|
+
onFocus={handleFocus}
|
|
69
|
+
onScroll={handleScroll}
|
|
70
|
+
>
|
|
71
|
+
<MoreSelect<V>
|
|
72
|
+
{...rest}
|
|
73
|
+
disabled={disabled}
|
|
74
|
+
ref={targetRef}
|
|
75
|
+
popoverType='realFocus'
|
|
76
|
+
onKeyDown={handleKeyDown}
|
|
77
|
+
isKeyboard
|
|
78
|
+
/>
|
|
79
|
+
</KeyboardCell>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default forwardRef(KCMoreSelect)
|
package/src/cell/select.tsx
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import React, { useRef, KeyboardEvent } from 'react'
|
|
2
|
-
import { Select, SelectProps } 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
|
-
function KCSelect<V = any>({ disabled, onKeyDown, ...rest }: SelectProps<V>) {
|
|
10
|
-
const cellRef = useRef<KeyboardCell>(null)
|
|
11
|
-
const targetRef = useRef<Select>(null)
|
|
12
|
-
const { wrapData, cellKey } = useContextData()
|
|
13
|
-
|
|
14
|
-
const handleFocus = () => {
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
targetRef.current?.apiDoFocus()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
20
|
-
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const handleKeyDown = (event: KeyboardEvent) => {
|
|
24
|
-
onKeyDown && onKeyDown(event)
|
|
25
|
-
if (
|
|
26
|
-
event.key === 'ArrowUp' ||
|
|
27
|
-
event.key === 'ArrowRight' ||
|
|
28
|
-
event.key === 'ArrowDown' ||
|
|
29
|
-
event.key === 'ArrowLeft'
|
|
30
|
-
) {
|
|
31
|
-
// 需要阻止
|
|
32
|
-
// 如果下一个是 input,切过去的时候光标会右移一位
|
|
33
|
-
event.preventDefault()
|
|
34
|
-
// eslint-disable-next-line
|
|
35
|
-
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
36
|
-
} else if (event.key === 'Tab') {
|
|
37
|
-
event.preventDefault()
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
cellRef.current?.apiDoTab()
|
|
40
|
-
} else if (event.key === 'Enter') {
|
|
41
|
-
event.preventDefault()
|
|
42
|
-
// Enter 要选择
|
|
43
|
-
// eslint-disable-next-line
|
|
44
|
-
targetRef.current?.apiDoSelectWillActive()
|
|
45
|
-
// eslint-disable-next-line
|
|
46
|
-
cellRef.current?.apiDoEnter()
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<KeyboardCell
|
|
52
|
-
ref={cellRef}
|
|
53
|
-
wrapData={wrapData}
|
|
54
|
-
cellKey={cellKey}
|
|
55
|
-
disabled={disabled}
|
|
56
|
-
onFocus={handleFocus}
|
|
57
|
-
onScroll={handleScroll}
|
|
58
|
-
>
|
|
59
|
-
<Select
|
|
60
|
-
{...rest}
|
|
61
|
-
ref={targetRef}
|
|
62
|
-
popoverType='realFocus'
|
|
63
|
-
disabled={disabled}
|
|
64
|
-
onKeyDown={handleKeyDown}
|
|
65
|
-
/>
|
|
66
|
-
</KeyboardCell>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default KCSelect
|
|
1
|
+
import React, { useRef, KeyboardEvent } from 'react'
|
|
2
|
+
import { Select, SelectProps } 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
|
+
function KCSelect<V = any>({ disabled, onKeyDown, ...rest }: SelectProps<V>) {
|
|
10
|
+
const cellRef = useRef<KeyboardCell>(null)
|
|
11
|
+
const targetRef = useRef<Select>(null)
|
|
12
|
+
const { wrapData, cellKey } = useContextData()
|
|
13
|
+
|
|
14
|
+
const handleFocus = () => {
|
|
15
|
+
// eslint-disable-next-line
|
|
16
|
+
targetRef.current?.apiDoFocus()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const handleScroll = (fixedWidths: KeyboardWrapData['fixedWidths']) => {
|
|
20
|
+
scrollIntoViewFixedWidth(findDOMNode(targetRef.current!) as HTMLElement, fixedWidths)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
24
|
+
onKeyDown && onKeyDown(event)
|
|
25
|
+
if (
|
|
26
|
+
event.key === 'ArrowUp' ||
|
|
27
|
+
event.key === 'ArrowRight' ||
|
|
28
|
+
event.key === 'ArrowDown' ||
|
|
29
|
+
event.key === 'ArrowLeft'
|
|
30
|
+
) {
|
|
31
|
+
// 需要阻止
|
|
32
|
+
// 如果下一个是 input,切过去的时候光标会右移一位
|
|
33
|
+
event.preventDefault()
|
|
34
|
+
// eslint-disable-next-line
|
|
35
|
+
cellRef.current?.apiDoDirectionByEventKey(event.key)
|
|
36
|
+
} else if (event.key === 'Tab') {
|
|
37
|
+
event.preventDefault()
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
cellRef.current?.apiDoTab()
|
|
40
|
+
} else if (event.key === 'Enter') {
|
|
41
|
+
event.preventDefault()
|
|
42
|
+
// Enter 要选择
|
|
43
|
+
// eslint-disable-next-line
|
|
44
|
+
targetRef.current?.apiDoSelectWillActive()
|
|
45
|
+
// eslint-disable-next-line
|
|
46
|
+
cellRef.current?.apiDoEnter()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<KeyboardCell
|
|
52
|
+
ref={cellRef}
|
|
53
|
+
wrapData={wrapData}
|
|
54
|
+
cellKey={cellKey}
|
|
55
|
+
disabled={disabled}
|
|
56
|
+
onFocus={handleFocus}
|
|
57
|
+
onScroll={handleScroll}
|
|
58
|
+
>
|
|
59
|
+
<Select
|
|
60
|
+
{...rest}
|
|
61
|
+
ref={targetRef}
|
|
62
|
+
popoverType='realFocus'
|
|
63
|
+
disabled={disabled}
|
|
64
|
+
onKeyDown={handleKeyDown}
|
|
65
|
+
/>
|
|
66
|
+
</KeyboardCell>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default KCSelect
|