@gm-pc/react 1.17.0-beta.1 → 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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-pc/react",
|
|
3
|
-
"version": "1.17.0-beta.
|
|
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",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@gm-common/hooks": "^2.10.0",
|
|
26
26
|
"@gm-common/tool": "^2.10.0",
|
|
27
|
-
"@gm-pc/locales": "^1.17.0-beta.
|
|
27
|
+
"@gm-pc/locales": "^1.17.0-beta.10",
|
|
28
28
|
"big.js": "^6.0.1",
|
|
29
29
|
"classnames": "^2.2.5",
|
|
30
30
|
"lodash": "^4.17.19",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react-router-dom": "^5.2.0",
|
|
49
49
|
"react-window": "^1.8.5"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b7017b352488f540d5108043888c7bea8d2c499a"
|
|
52
52
|
}
|
|
@@ -82,6 +82,7 @@ const AutoComplete = forwardRef<AutoCompleteRef, AutoCompleteProps>((props, ref)
|
|
|
82
82
|
const inputNode = useRef<HTMLInputElement | null>(null)
|
|
83
83
|
|
|
84
84
|
const triggerPopover = (value: boolean) => {
|
|
85
|
+
if (value === true && options.length <= 0) return
|
|
85
86
|
popoverNode.current && popoverNode.current.apiDoSetActive(value)
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -97,13 +98,25 @@ const AutoComplete = forwardRef<AutoCompleteRef, AutoCompleteProps>((props, ref)
|
|
|
97
98
|
}, [value, options])
|
|
98
99
|
|
|
99
100
|
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
100
|
-
if (
|
|
101
|
+
if (event.key === 'Enter') {
|
|
102
|
+
if (willActiveIndex >= 0) {
|
|
103
|
+
const val = options[willActiveIndex]?.value
|
|
104
|
+
if (!_.isNil(val) && value !== val) {
|
|
105
|
+
onChange && onChange(val)
|
|
106
|
+
triggerPopover(false)
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
if (popoverVisible.current) {
|
|
110
|
+
triggerPopover(false)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
}
|
|
101
114
|
onKeyDown && onKeyDown(event)
|
|
102
115
|
return
|
|
103
116
|
}
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
if (!popoverVisible.current) {
|
|
118
|
+
onKeyDown && onKeyDown(event)
|
|
119
|
+
return
|
|
107
120
|
}
|
|
108
121
|
if (event.key === 'Escape') {
|
|
109
122
|
triggerPopover(false)
|
|
@@ -113,26 +126,15 @@ const AutoComplete = forwardRef<AutoCompleteRef, AutoCompleteProps>((props, ref)
|
|
|
113
126
|
return
|
|
114
127
|
}
|
|
115
128
|
let index = willActiveIndex
|
|
116
|
-
if (event.key === 'ArrowUp' && index === 0) {
|
|
117
|
-
event.preventDefault()
|
|
118
|
-
onKeyDown && onKeyDown(event)
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
if (event.key === 'ArrowDown' && index === options.length - 1) {
|
|
122
|
-
event.preventDefault()
|
|
123
|
-
onKeyDown && onKeyDown(event)
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
event.preventDefault()
|
|
127
129
|
if (event.key === 'ArrowUp') {
|
|
128
|
-
index
|
|
130
|
+
index--
|
|
129
131
|
} else if (event.key === 'ArrowDown') {
|
|
130
|
-
index
|
|
132
|
+
index++
|
|
131
133
|
}
|
|
132
134
|
if (index < 0) {
|
|
133
|
-
index = 0
|
|
134
|
-
} else if (index > options.length - 1) {
|
|
135
135
|
index = options.length - 1
|
|
136
|
+
} else if (index > options.length - 1) {
|
|
137
|
+
index = 0
|
|
136
138
|
}
|
|
137
139
|
setWillActiveIndex(index)
|
|
138
140
|
}
|
|
@@ -188,9 +190,7 @@ const AutoComplete = forwardRef<AutoCompleteRef, AutoCompleteProps>((props, ref)
|
|
|
188
190
|
value={value}
|
|
189
191
|
onChange={(e) => {
|
|
190
192
|
const val = e.target.value
|
|
191
|
-
|
|
192
|
-
triggerPopover(true)
|
|
193
|
-
}
|
|
193
|
+
triggerPopover(val.length === 0)
|
|
194
194
|
onChange && onChange(val)
|
|
195
195
|
}}
|
|
196
196
|
onBlur={(e) => {
|
|
@@ -46,6 +46,8 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
46
46
|
private _baseRef = createRef<HTMLDivElement>()
|
|
47
47
|
private _selectionRef = createRef<HTMLDivElement>()
|
|
48
48
|
private _popoverRef = createRef<Popover>()
|
|
49
|
+
private _inputRef = createRef<HTMLInputElement>()
|
|
50
|
+
|
|
49
51
|
private _filterData: MoreSelectGroupDataItem<V>[] | undefined
|
|
50
52
|
|
|
51
53
|
constructor(props: MoreSelectBaseProps<V>) {
|
|
@@ -123,10 +125,18 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
public _handleChange = (
|
|
128
|
+
public _handleChange = (
|
|
129
|
+
event: ChangeEvent<HTMLInputElement>,
|
|
130
|
+
isInitSearch?: boolean
|
|
131
|
+
): void => {
|
|
127
132
|
const searchValue = event.target.value
|
|
128
133
|
this.setState({ searchValue })
|
|
129
134
|
this._debounceDoSearch(searchValue)
|
|
135
|
+
console.log(this._inputRef.current, this._baseRef, 'this._inputRef.current')
|
|
136
|
+
setTimeout(() => {
|
|
137
|
+
// eslint-disable-next-line no-unused-expressions
|
|
138
|
+
isInitSearch && this._inputRef.current?.select()
|
|
139
|
+
}, 100)
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
private _doSearch = (query: string): void => {
|
|
@@ -239,6 +249,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
239
249
|
>
|
|
240
250
|
<div className='gm-more-select-popup-input'>
|
|
241
251
|
<Input
|
|
252
|
+
ref={this._inputRef}
|
|
242
253
|
autoFocus
|
|
243
254
|
value={searchValue}
|
|
244
255
|
onChange={this._handleChange}
|
|
@@ -53,9 +53,12 @@ class MoreSelect<V = any> extends Component<MoreSelectProps<V>> {
|
|
|
53
53
|
|
|
54
54
|
public _handleInitSearch = (q?: string) => {
|
|
55
55
|
// eslint-disable-next-line no-unused-expressions
|
|
56
|
-
this._moreSelectBaseRef?.current?._handleChange(
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
this._moreSelectBaseRef?.current?._handleChange(
|
|
57
|
+
{
|
|
58
|
+
target: { value: q },
|
|
59
|
+
} as ChangeEvent<HTMLInputElement>,
|
|
60
|
+
true
|
|
61
|
+
)
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
_renderListFilter = (data: MoreSelectGroupDataItem<V>[], searchValue: string) => {
|