@@ -13,9 +13,12 @@ import type {
1313 OptionData ,
1414 RenderNode ,
1515 OnActiveValue ,
16+ FieldNames ,
1617} from './interface' ;
1718import type { RawValueType , FlattenOptionsType } from './interface/generator' ;
19+ import { fillFieldNames } from './utils/valueUtil' ;
1820import useMemo from '../_util/hooks/useMemo' ;
21+ import { isPlatformMac } from './utils/platformUtil' ;
1922
2023export interface RefOptionListProps {
2124 onKeydown : ( e ?: KeyboardEvent ) => void ;
@@ -24,10 +27,12 @@ export interface RefOptionListProps {
2427}
2528
2629import type { EventHandler } from '../_util/EventInterface' ;
30+ import omit from '../_util/omit' ;
2731export interface OptionListProps < OptionType extends object > {
2832 prefixCls : string ;
2933 id : string ;
3034 options : OptionType [ ] ;
35+ fieldNames ?: FieldNames ;
3136 flattenOptions : FlattenOptionsType < OptionType > ;
3237 height : number ;
3338 itemHeight : number ;
@@ -40,6 +45,7 @@ export interface OptionListProps<OptionType extends object> {
4045 childrenAsData : boolean ;
4146 searchValue : string ;
4247 virtual : boolean ;
48+ direction ?: 'ltr' | 'rtl' ;
4349
4450 onSelect : ( value : RawValueType , option : { selected : boolean } ) => void ;
4551 onToggleOpen : ( open ?: boolean ) => void ;
@@ -55,6 +61,7 @@ const OptionListProps = {
5561 prefixCls : PropTypes . string ,
5662 id : PropTypes . string ,
5763 options : PropTypes . array ,
64+ fieldNames : PropTypes . object ,
5865 flattenOptions : PropTypes . array ,
5966 height : PropTypes . number ,
6067 itemHeight : PropTypes . number ,
@@ -67,6 +74,7 @@ const OptionListProps = {
6774 childrenAsData : PropTypes . looseBool ,
6875 searchValue : PropTypes . string ,
6976 virtual : PropTypes . looseBool ,
77+ direction : PropTypes . string ,
7078
7179 onSelect : PropTypes . func ,
7280 onToggleOpen : { type : Function as PropType < ( open ?: boolean ) => void > } ,
@@ -153,15 +161,17 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
153161 // Auto scroll to item position in single mode
154162
155163 watch (
156- ( ) => props . open ,
164+ [ ( ) => props . open , ( ) => props . searchValue ] ,
157165 ( ) => {
158166 if ( ! props . multiple && props . open && props . values . size === 1 ) {
159167 const value = Array . from ( props . values ) [ 0 ] ;
160168 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+ }
165175 }
166176 // Force trigger scrollbar visible when open
167177 if ( props . open ) {
@@ -216,16 +226,24 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
216226 setActive,
217227 onSelectValue,
218228 onKeydown : ( event : KeyboardEvent ) => {
219- const { which } = event ;
229+ const { which, ctrlKey } = event ;
220230 switch ( which ) {
221- // >>> Arrow keys
231+ // >>> Arrow keys & ctrl + n/p on Mac
232+ case KeyCode . N :
233+ case KeyCode . P :
222234 case KeyCode . UP :
223235 case KeyCode . DOWN : {
224236 let offset = 0 ;
225237 if ( which === KeyCode . UP ) {
226238 offset = - 1 ;
227239 } else if ( which === KeyCode . DOWN ) {
228240 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+ }
229247 }
230248
231249 if ( offset !== 0 ) {
@@ -290,11 +308,13 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
290308 menuItemSelectedIcon,
291309 notFoundContent,
292310 virtual,
311+ fieldNames,
293312 onScroll,
294313 onMouseenter,
295314 } = this . $props ;
296315 const renderOption = $slots . option ;
297316 const { activeIndex } = this . state ;
317+ const omitFieldNameList = Object . values ( fillFieldNames ( fieldNames ) ) ;
298318 // ========================== Render ==========================
299319 if ( memoFlattenOptions . length === 0 ) {
300320 return (
@@ -326,8 +346,8 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
326346 onScroll = { onScroll }
327347 virtual = { virtual }
328348 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 ;
331351 // Group
332352 if ( group ) {
333353 return (
@@ -337,17 +357,8 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
337357 ) ;
338358 }
339359
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 ) ;
351362 // Option
352363 const selected = values . has ( value ) ;
353364
@@ -376,7 +387,7 @@ const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, {
376387
377388 return (
378389 < div
379- { ...otherProps }
390+ { ...passedProps }
380391 aria-selected = { selected }
381392 class = { optionClassName }
382393 title = { optionTitle }
0 commit comments