11import { cloneElement } from '../../_util/vnode' ;
2- import type { VNode } from 'vue' ;
2+ import type { ExtractPropTypes , PropType , VNode } from 'vue' ;
33import { defineComponent , getCurrentInstance , inject , onMounted , withDirectives } from 'vue' ;
44import PropTypes from '../../_util/vue-types' ;
5- import type { RefObject } from '../../_util/createRef' ;
65import antInput from '../../_util/antInputDirective' ;
76import classNames from '../../_util/classNames' ;
8- import type { EventHandler } from '../../_util/EventInterface' ;
9- import type { VueNode } from '../../_util/type' ;
7+ import type {
8+ FocusEventHandler ,
9+ KeyboardEventHandler ,
10+ MouseEventHandler ,
11+ ChangeEventHandler ,
12+ CompositionEventHandler ,
13+ ClipboardEventHandler ,
14+ } from '../../_util/EventInterface' ;
1015
11- interface InputProps {
12- prefixCls : string ;
13- id : string ;
14- inputElement : VueNode ;
15- disabled : boolean ;
16- autofocus : boolean ;
17- autocomplete : string ;
18- editable : boolean ;
19- activeDescendantId ?: string ;
20- value : string ;
21- open : boolean ;
22- tabindex : number | string ;
16+ export const inputProps = {
17+ inputRef : PropTypes . any ,
18+ prefixCls : PropTypes . string ,
19+ id : PropTypes . string ,
20+ inputElement : PropTypes . VueNode ,
21+ disabled : PropTypes . looseBool ,
22+ autofocus : PropTypes . looseBool ,
23+ autocomplete : PropTypes . string ,
24+ editable : PropTypes . looseBool ,
25+ activeDescendantId : PropTypes . string ,
26+ value : PropTypes . string ,
27+ open : PropTypes . looseBool ,
28+ tabindex : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
2329 /** Pass accessibility props to input */
24- attrs : object ;
25- inputRef : RefObject ;
26- onKeydown : EventHandler ;
27- onMousedown : EventHandler ;
28- onChange : EventHandler ;
29- onPaste : EventHandler ;
30- onCompositionstart : EventHandler ;
31- onCompositionend : EventHandler ;
32- onFocus : EventHandler ;
33- onBlur : EventHandler ;
34- }
30+ attrs : PropTypes . object ,
31+ onKeydown : { type : Function as PropType < KeyboardEventHandler > } ,
32+ onMousedown : { type : Function as PropType < MouseEventHandler > } ,
33+ onChange : { type : Function as PropType < ChangeEventHandler > } ,
34+ onPaste : { type : Function as PropType < ClipboardEventHandler > } ,
35+ onCompositionstart : { type : Function as PropType < CompositionEventHandler > } ,
36+ onCompositionend : { type : Function as PropType < CompositionEventHandler > } ,
37+ onFocus : { type : Function as PropType < FocusEventHandler > } ,
38+ onBlur : { type : Function as PropType < FocusEventHandler > } ,
39+ } ;
40+
41+ export type InputProps = Partial < ExtractPropTypes < typeof inputProps > > ;
3542
3643const Input = defineComponent ( {
3744 name : 'Input' ,
3845 inheritAttrs : false ,
39- props : {
40- inputRef : PropTypes . any ,
41- prefixCls : PropTypes . string ,
42- id : PropTypes . string ,
43- inputElement : PropTypes . any ,
44- disabled : PropTypes . looseBool ,
45- autofocus : PropTypes . looseBool ,
46- autocomplete : PropTypes . string ,
47- editable : PropTypes . looseBool ,
48- activeDescendantId : PropTypes . string ,
49- value : PropTypes . string ,
50- open : PropTypes . looseBool ,
51- tabindex : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
52- /** Pass accessibility props to input */
53- attrs : PropTypes . object ,
54- onKeydown : PropTypes . func ,
55- onMousedown : PropTypes . func ,
56- onChange : PropTypes . func ,
57- onPaste : PropTypes . func ,
58- onCompositionstart : PropTypes . func ,
59- onCompositionend : PropTypes . func ,
60- onFocus : PropTypes . func ,
61- onBlur : PropTypes . func ,
62- } ,
46+ props : inputProps ,
6347 setup ( props ) {
48+ let blurTimeout = null ;
49+ const VCSelectContainerEvent = inject ( 'VCSelectContainerEvent' ) as any ;
50+
6451 if ( process . env . NODE_ENV === 'test' ) {
6552 onMounted ( ( ) => {
6653 const ins = getCurrentInstance ( ) ;
@@ -71,122 +58,120 @@ const Input = defineComponent({
7158 }
7259 } ) ;
7360 }
74- return {
75- blurTimeout : null ,
76- VCSelectContainerEvent : inject ( 'VCSelectContainerEvent' ) as any ,
77- } ;
78- } ,
79- render ( ) {
80- const {
81- prefixCls,
82- id,
83- inputElement,
84- disabled,
85- tabindex,
86- autofocus,
87- autocomplete,
88- editable,
89- activeDescendantId,
90- value,
91- onKeydown,
92- onMousedown,
93- onChange,
94- onPaste,
95- onCompositionstart,
96- onCompositionend,
97- onFocus,
98- onBlur,
99- open,
100- inputRef,
101- attrs,
102- } = this . $props as InputProps ;
103- let inputNode : any = inputElement || withDirectives ( ( < input /> ) as VNode , [ [ antInput ] ] ) ;
10461
105- const inputProps = inputNode . props || { } ;
106- const {
107- onKeydown : onOriginKeyDown ,
108- onInput : onOriginInput ,
109- onFocus : onOriginFocus ,
110- onBlur : onOriginBlur ,
111- onMousedown : onOriginMouseDown ,
112- onCompositionstart : onOriginCompositionStart ,
113- onCompositionend : onOriginCompositionEnd ,
114- style,
115- } = inputProps ;
116- inputNode = cloneElement (
117- inputNode ,
118- Object . assign (
119- {
120- id,
121- ref : inputRef ,
122- disabled,
123- tabindex,
124- autocomplete : autocomplete || 'off' ,
125- autofocus,
126- class : classNames ( `${ prefixCls } -selection-search-input` , inputNode ?. props ?. className ) ,
127- style : { ...style , opacity : editable ? null : 0 } ,
128- role : 'combobox' ,
129- 'aria-expanded' : open ,
130- 'aria-haspopup' : 'listbox' ,
131- 'aria-owns' : `${ id } _list` ,
132- 'aria-autocomplete' : 'list' ,
133- 'aria-controls' : `${ id } _list` ,
134- 'aria-activedescendant' : activeDescendantId ,
135- ...attrs ,
136- value : editable ? value : '' ,
137- readonly : ! editable ,
138- unselectable : ! editable ? 'on' : null ,
139- onKeydown : ( event : KeyboardEvent ) => {
140- onKeydown ( event ) ;
141- if ( onOriginKeyDown ) {
142- onOriginKeyDown ( event ) ;
143- }
144- } ,
145- onMousedown : ( event : MouseEvent ) => {
146- onMousedown ( event ) ;
147- if ( onOriginMouseDown ) {
148- onOriginMouseDown ( event ) ;
149- }
150- } ,
151- onInput : ( event : Event ) => {
152- onChange ( event ) ;
153- if ( onOriginInput ) {
154- onOriginInput ( event ) ;
155- }
156- } ,
157- onCompositionstart ( event : CompositionEvent ) {
158- onCompositionstart ( event ) ;
159- if ( onOriginCompositionStart ) {
160- onOriginCompositionStart ( event ) ;
161- }
162- } ,
163- onCompositionend ( event : CompositionEvent ) {
164- onCompositionend ( event ) ;
165- if ( onOriginCompositionEnd ) {
166- onOriginCompositionEnd ( event ) ;
167- }
168- } ,
169- onPaste,
170- onFocus : ( ...args : any [ ] ) => {
171- clearTimeout ( this . blurTimeout ) ;
172- onOriginFocus && onOriginFocus ( args [ 0 ] ) ;
173- onFocus && onFocus ( args [ 0 ] ) ;
174- this . VCSelectContainerEvent ?. focus ( args [ 0 ] ) ;
175- } ,
176- onBlur : ( ...args : any [ ] ) => {
177- this . blurTimeout = setTimeout ( ( ) => {
178- onOriginBlur && onOriginBlur ( args [ 0 ] ) ;
179- onBlur && onBlur ( args [ 0 ] ) ;
180- this . VCSelectContainerEvent ?. blur ( args [ 0 ] ) ;
181- } , 100 ) ;
62+ return ( ) => {
63+ const {
64+ prefixCls,
65+ id,
66+ inputElement,
67+ disabled,
68+ tabindex,
69+ autofocus,
70+ autocomplete,
71+ editable,
72+ activeDescendantId,
73+ value,
74+ onKeydown,
75+ onMousedown,
76+ onChange,
77+ onPaste,
78+ onCompositionstart,
79+ onCompositionend,
80+ onFocus,
81+ onBlur,
82+ open,
83+ inputRef,
84+ attrs,
85+ } = props ;
86+
87+ let inputNode : any = inputElement || withDirectives ( ( < input /> ) as VNode , [ [ antInput ] ] ) ;
88+
89+ const inputProps = inputNode . props || { } ;
90+ const {
91+ onKeydown : onOriginKeyDown ,
92+ onInput : onOriginInput ,
93+ onFocus : onOriginFocus ,
94+ onBlur : onOriginBlur ,
95+ onMousedown : onOriginMouseDown ,
96+ onCompositionstart : onOriginCompositionStart ,
97+ onCompositionend : onOriginCompositionEnd ,
98+ style,
99+ } = inputProps ;
100+ inputNode = cloneElement (
101+ inputNode ,
102+ Object . assign (
103+ {
104+ id,
105+ ref : inputRef ,
106+ disabled,
107+ tabindex,
108+ autocomplete : autocomplete || 'off' ,
109+ autofocus,
110+ class : classNames ( `${ prefixCls } -selection-search-input` , inputNode ?. props ?. class ) ,
111+ style : { ...style , opacity : editable ? null : 0 } ,
112+ role : 'combobox' ,
113+ 'aria-expanded' : open ,
114+ 'aria-haspopup' : 'listbox' ,
115+ 'aria-owns' : `${ id } _list` ,
116+ 'aria-autocomplete' : 'list' ,
117+ 'aria-controls' : `${ id } _list` ,
118+ 'aria-activedescendant' : activeDescendantId ,
119+ ...attrs ,
120+ value : editable ? value : '' ,
121+ readonly : ! editable ,
122+ unselectable : ! editable ? 'on' : null ,
123+ onKeydown : ( event : KeyboardEvent ) => {
124+ onKeydown ( event ) ;
125+ if ( onOriginKeyDown ) {
126+ onOriginKeyDown ( event ) ;
127+ }
128+ } ,
129+ onMousedown : ( event : MouseEvent ) => {
130+ onMousedown ( event ) ;
131+ if ( onOriginMouseDown ) {
132+ onOriginMouseDown ( event ) ;
133+ }
134+ } ,
135+ onInput : ( event : Event ) => {
136+ onChange ( event ) ;
137+ if ( onOriginInput ) {
138+ onOriginInput ( event ) ;
139+ }
140+ } ,
141+ onCompositionstart ( event : CompositionEvent ) {
142+ onCompositionstart ( event ) ;
143+ if ( onOriginCompositionStart ) {
144+ onOriginCompositionStart ( event ) ;
145+ }
146+ } ,
147+ onCompositionend ( event : CompositionEvent ) {
148+ onCompositionend ( event ) ;
149+ if ( onOriginCompositionEnd ) {
150+ onOriginCompositionEnd ( event ) ;
151+ }
152+ } ,
153+ onPaste,
154+ onFocus : ( ...args : any [ ] ) => {
155+ clearTimeout ( blurTimeout ) ;
156+ onOriginFocus && onOriginFocus ( args [ 0 ] ) ;
157+ onFocus && onFocus ( args [ 0 ] ) ;
158+ VCSelectContainerEvent ?. focus ( args [ 0 ] ) ;
159+ } ,
160+ onBlur : ( ...args : any [ ] ) => {
161+ blurTimeout = setTimeout ( ( ) => {
162+ onOriginBlur && onOriginBlur ( args [ 0 ] ) ;
163+ onBlur && onBlur ( args [ 0 ] ) ;
164+ VCSelectContainerEvent ?. blur ( args [ 0 ] ) ;
165+ } , 100 ) ;
166+ } ,
182167 } ,
183- } ,
184- inputNode . type === 'textarea' ? { } : { type : 'search' } ,
185- ) ,
186- true ,
187- true ,
188- ) as VNode ;
189- return inputNode ;
168+ inputNode . type === 'textarea' ? { } : { type : 'search' } ,
169+ ) ,
170+ true ,
171+ true ,
172+ ) as VNode ;
173+ return inputNode ;
174+ } ;
190175 } ,
191176} ) ;
192177
0 commit comments