@@ -2,13 +2,10 @@ import type { SelectProps } from 'rc-select';
22import type { OptionProps } from 'rc-select/es/Option' ;
33import KEYCODE from 'rc-util/lib/KeyCode' ;
44import classNames from 'classnames' ;
5- import React from 'react' ;
5+ import React , { useState } from 'react' ;
66import type { PaginationLocale , PaginationProps } from './interface' ;
77
88interface InternalSelectProps extends SelectProps {
9- /**
10- * form antd v5.5.0, popupMatchSelectWidth default is true
11- */
129 popupMatchSelectWidth ?: boolean ;
1310}
1411
@@ -31,26 +28,24 @@ interface OptionsProps {
3128
3229const defaultPageSizeOptions = [ '10' , '20' , '50' , '100' ] ;
3330
34- const Options : React . FC < OptionsProps > = ( props ) => {
35- const {
36- pageSizeOptions = defaultPageSizeOptions ,
37- locale,
38- changeSize,
39- pageSize,
40- goButton,
41- quickGo,
42- rootPrefixCls,
43- selectComponentClass : Select ,
44- selectPrefixCls,
45- disabled,
46- buildOptionText,
47- showSizeChanger,
48- } = props ;
49-
50- const [ goInputText , setGoInputText ] = React . useState ( '' ) ;
31+ const Options : React . FC < OptionsProps > = ( {
32+ pageSizeOptions = defaultPageSizeOptions ,
33+ locale,
34+ changeSize,
35+ pageSize,
36+ goButton,
37+ quickGo,
38+ rootPrefixCls,
39+ selectComponentClass : Select ,
40+ selectPrefixCls,
41+ disabled,
42+ buildOptionText,
43+ showSizeChanger,
44+ } ) => {
45+ const [ goInputText , setGoInputText ] = useState ( '' ) ;
5146
5247 const getValidValue = ( ) => {
53- return ! goInputText || Number . isNaN ( goInputText )
48+ return ! goInputText || isNaN ( Number ( goInputText ) )
5449 ? undefined
5550 : Number ( goInputText ) ;
5651 } ;
@@ -71,25 +66,20 @@ const Options: React.FC<OptionsProps> = (props) => {
7166 setGoInputText ( e . target . value ) ;
7267 } ;
7368
74- const handleBlur = ( e : React . FocusEvent < HTMLInputElement , Element > ) => {
75- if ( goButton || goInputText === '' ) {
76- return ;
77- }
69+ const handleBlur = ( e : React . FocusEvent < HTMLInputElement > ) => {
70+ if ( goButton || goInputText === '' ) return ;
7871 setGoInputText ( '' ) ;
7972 if (
8073 e . relatedTarget &&
81- ( e . relatedTarget . className . indexOf ( `${ rootPrefixCls } -item-link` ) >= 0 ||
82- e . relatedTarget . className . indexOf ( `${ rootPrefixCls } -item` ) >= 0 )
83- ) {
74+ ( e . relatedTarget . className . includes ( `${ rootPrefixCls } -item-link` ) ||
75+ e . relatedTarget . className . includes ( `${ rootPrefixCls } -item` ) )
76+ )
8477 return ;
85- }
8678 quickGo ?.( getValidValue ( ) ) ;
8779 } ;
8880
89- const go = ( e : any ) => {
90- if ( goInputText === '' ) {
91- return ;
92- }
81+ const go = ( e : React . KeyboardEvent < HTMLInputElement > | React . MouseEvent ) => {
82+ if ( goInputText === '' ) return ;
9383 if ( e . keyCode === KEYCODE . ENTER || e . type === 'click' ) {
9484 setGoInputText ( '' ) ;
9585 quickGo ?.( getValidValue ( ) ) ;
@@ -104,20 +94,14 @@ const Options: React.FC<OptionsProps> = (props) => {
10494 ) {
10595 return pageSizeOptions ;
10696 }
107- return pageSizeOptions . concat ( [ pageSize . toString ( ) ] ) . sort ( ( a , b ) => {
108- const numberA = Number . isNaN ( Number ( a ) ) ? 0 : Number ( a ) ;
109- const numberB = Number . isNaN ( Number ( b ) ) ? 0 : Number ( b ) ;
110- return numberA - numberB ;
111- } ) ;
97+ return [ ...pageSizeOptions , pageSize . toString ( ) ] . sort (
98+ ( a , b ) => Number ( a ) - Number ( b ) ,
99+ ) ;
112100 } ;
113- // ============== cls ==============
114- const prefixCls = `${ rootPrefixCls } -options` ;
115101
116- // ============== render ==============
102+ const prefixCls = ` ${ rootPrefixCls } -options` ;
117103
118- if ( ! showSizeChanger && ! quickGo ) {
119- return null ;
120- }
104+ if ( ! showSizeChanger && ! quickGo ) return null ;
121105
122106 let changeSelect : React . ReactNode = null ;
123107 let goInput : React . ReactNode = null ;
@@ -127,11 +111,7 @@ const Options: React.FC<OptionsProps> = (props) => {
127111 const {
128112 options : showSizeChangerOptions ,
129113 className : showSizeChangerClassName ,
130- } =
131- typeof showSizeChanger === 'object'
132- ? showSizeChanger
133- : ( { } as SelectProps ) ;
134- // use showSizeChanger.options if existed, otherwise use pageSizeOptions
114+ } = typeof showSizeChanger === 'object' ? showSizeChanger : { } ;
135115 const options = showSizeChangerOptions
136116 ? undefined
137117 : getPageSizeOptions ( ) . map ( ( opt , i ) => (
0 commit comments