@@ -13,9 +13,12 @@ import type {
13
13
OptionData ,
14
14
RenderNode ,
15
15
OnActiveValue ,
16
+ FieldNames ,
16
17
} from './interface' ;
17
18
import type { RawValueType , FlattenOptionsType } from './interface/generator' ;
19
+ import { fillFieldNames } from './utils/valueUtil' ;
18
20
import useMemo from '../_util/hooks/useMemo' ;
21
+ import { isPlatformMac } from './utils/platformUtil' ;
19
22
20
23
export interface RefOptionListProps {
21
24
onKeydown : ( e ?: KeyboardEvent ) => void ;
@@ -24,10 +27,12 @@ export interface RefOptionListProps {
24
27
}
25
28
26
29
import type { EventHandler } from '../_util/EventInterface' ;
30
+ import omit from '../_util/omit' ;
27
31
export interface OptionListProps < OptionType extends object > {
28
32
prefixCls : string ;
29
33
id : string ;
30
34
options : OptionType [ ] ;
35
+ fieldNames ?: FieldNames ;
31
36
flattenOptions : FlattenOptionsType < OptionType > ;
32
37
height : number ;
33
38
itemHeight : number ;
@@ -40,6 +45,7 @@ export interface OptionListProps<OptionType extends object> {
40
45
childrenAsData : boolean ;
41
46
searchValue : string ;
42
47
virtual : boolean ;
48
+ direction ?: 'ltr' | 'rtl' ;
43
49
44
50
onSelect : ( value : RawValueType , option : { selected : boolean } ) => void ;
45
51
onToggleOpen : ( open ?: boolean ) => void ;
@@ -55,6 +61,7 @@ const OptionListProps = {
55
61
prefixCls : PropTypes . string ,
56
62
id : PropTypes . string ,
57
63
options : PropTypes . array ,
64
+ fieldNames : PropTypes . object ,
58
65
flattenOptions : PropTypes . array ,
59
66
height : PropTypes . number ,
60
67
itemHeight : PropTypes . number ,
@@ -67,6 +74,7 @@ const OptionListProps = {
67
74
childrenAsData : PropTypes . looseBool ,
68
75
searchValue : PropTypes . string ,
69
76
virtual : PropTypes . looseBool ,
77
+ direction : PropTypes . string ,
70
78
71
79
onSelect : PropTypes . func ,
72
80
onToggleOpen : { type : Function as PropType < ( open ?: boolean ) => void > } ,
@@ -153,15 +161,17 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
153
161
// Auto scroll to item position in single mode
154
162
155
163
watch (
156
- ( ) => props . open ,
164
+ [ ( ) => props . open , ( ) => props . searchValue ] ,
157
165
( ) => {
158
166
if ( ! props . multiple && props . open && props . values . size === 1 ) {
159
167
const value = Array . from ( props . values ) [ 0 ] ;
160
168
const index = memoFlattenOptions . value . findIndex ( ( { data } ) => data . value === value ) ;
161
- setActive ( index ) ;
162
- nextTick ( ( ) => {
163
- scrollIntoView ( index ) ;
164
- } ) ;
169
+ if ( index !== - 1 ) {
170
+ setActive ( index ) ;
171
+ nextTick ( ( ) => {
172
+ scrollIntoView ( index ) ;
173
+ } ) ;
174
+ }
165
175
}
166
176
// Force trigger scrollbar visible when open
167
177
if ( props . open ) {
@@ -216,16 +226,24 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
216
226
setActive,
217
227
onSelectValue,
218
228
onKeydown : ( event : KeyboardEvent ) => {
219
- const { which } = event ;
229
+ const { which, ctrlKey } = event ;
220
230
switch ( which ) {
221
- // >>> Arrow keys
231
+ // >>> Arrow keys & ctrl + n/p on Mac
232
+ case KeyCode . N :
233
+ case KeyCode . P :
222
234
case KeyCode . UP :
223
235
case KeyCode . DOWN : {
224
236
let offset = 0 ;
225
237
if ( which === KeyCode . UP ) {
226
238
offset = - 1 ;
227
239
} else if ( which === KeyCode . DOWN ) {
228
240
offset = 1 ;
241
+ } else if ( isPlatformMac ( ) && ctrlKey ) {
242
+ if ( which === KeyCode . N ) {
243
+ offset = 1 ;
244
+ } else if ( which === KeyCode . P ) {
245
+ offset = - 1 ;
246
+ }
229
247
}
230
248
231
249
if ( offset !== 0 ) {
@@ -290,11 +308,13 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
290
308
menuItemSelectedIcon,
291
309
notFoundContent,
292
310
virtual,
311
+ fieldNames,
293
312
onScroll,
294
313
onMouseenter,
295
314
} = this . $props ;
296
315
const renderOption = $slots . option ;
297
316
const { activeIndex } = this . state ;
317
+ const omitFieldNameList = Object . values ( fillFieldNames ( fieldNames ) ) ;
298
318
// ========================== Render ==========================
299
319
if ( memoFlattenOptions . length === 0 ) {
300
320
return (
@@ -326,8 +346,8 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
326
346
onScroll = { onScroll }
327
347
virtual = { virtual }
328
348
onMouseenter = { onMouseenter }
329
- children = { ( { group, groupOption, data } , itemIndex ) => {
330
- const { label , key } = data ;
349
+ children = { ( { group, groupOption, data, label , value } , itemIndex ) => {
350
+ const { key } = data ;
331
351
// Group
332
352
if ( group ) {
333
353
return (
@@ -337,17 +357,8 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
337
357
) ;
338
358
}
339
359
340
- const {
341
- disabled,
342
- value,
343
- title,
344
- children,
345
- style,
346
- class : cls ,
347
- className,
348
- ...otherProps
349
- } = data ;
350
-
360
+ const { disabled, title, children, style, class : cls , className, ...otherProps } = data ;
361
+ const passedProps = omit ( otherProps , omitFieldNameList ) ;
351
362
// Option
352
363
const selected = values . has ( value ) ;
353
364
@@ -376,7 +387,7 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
376
387
377
388
return (
378
389
< div
379
- { ...otherProps }
390
+ { ...passedProps }
380
391
aria-selected = { selected }
381
392
class = { optionClassName }
382
393
title = { optionTitle }
0 commit comments