1
- import { computed , defineComponent , inject , ref , VNodeChild , App , PropType , Plugin } from 'vue' ;
1
+ import { computed , defineComponent , ref , VNodeChild , App , PropType , Plugin } from 'vue' ;
2
2
import omit from 'omit.js' ;
3
3
import classNames from '../_util/classNames' ;
4
4
import RcSelect , { Option , OptGroup , SelectProps as RcSelectProps , BaseProps } from '../vc-select' ;
5
5
import { OptionProps as OptionPropsType } from '../vc-select/Option' ;
6
- import { defaultConfigProvider } from '../config-provider' ;
7
6
import getIcons from './utils/iconUtil' ;
8
7
import PropTypes from '../_util/vue-types' ;
9
8
import { tuple } from '../_util/type' ;
9
+ import useConfigInject from '../_util/hooks/useConfigInject' ;
10
10
11
11
type RawValue = string | number ;
12
12
@@ -74,11 +74,10 @@ const Select = defineComponent({
74
74
props : SelectProps ( ) ,
75
75
SECRET_COMBOBOX_MODE_DO_NOT_USE : 'SECRET_COMBOBOX_MODE_DO_NOT_USE' ,
76
76
emits : [ 'change' , 'update:value' ] ,
77
- setup ( props : any , { attrs, emit } ) {
77
+ slots : [ 'notFoundContent' , 'suffixIcon' , 'itemIcon' , 'removeIcon' , 'clearIcon' , 'dropdownRender' ] ,
78
+ setup ( props , { attrs, emit, slots, expose } ) {
78
79
const selectRef = ref ( null ) ;
79
80
80
- const configProvider = inject ( 'configProvider' , defaultConfigProvider ) ;
81
-
82
81
const focus = ( ) => {
83
82
if ( selectRef . value ) {
84
83
selectRef . value . focus ( ) ;
@@ -104,122 +103,100 @@ const Select = defineComponent({
104
103
105
104
return mode ;
106
105
} ) ;
107
- const prefixCls = computed ( ( ) => {
108
- return configProvider . getPrefixCls ( 'select' , props . prefixCls ) ;
109
- } ) ;
106
+ const { prefixCls, direction, configProvider } = useConfigInject ( 'select' , props ) ;
110
107
const mergedClassName = computed ( ( ) =>
111
- classNames (
112
- {
113
- [ `${ prefixCls . value } -lg` ] : props . size === 'large' ,
114
- [ `${ prefixCls . value } -sm` ] : props . size === 'small' ,
115
- [ `${ prefixCls . value } -rtl` ] : props . direction === 'rtl' ,
116
- [ `${ prefixCls . value } -borderless` ] : ! props . bordered ,
117
- } ,
118
- attrs . class ,
119
- ) ,
108
+ classNames ( {
109
+ [ `${ prefixCls . value } -lg` ] : props . size === 'large' ,
110
+ [ `${ prefixCls . value } -sm` ] : props . size === 'small' ,
111
+ [ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
112
+ [ `${ prefixCls . value } -borderless` ] : ! props . bordered ,
113
+ } ) ,
120
114
) ;
121
115
const triggerChange = ( ...args : any [ ] ) => {
122
116
emit ( 'update:value' , args [ 0 ] ) ;
123
117
emit ( 'change' , ...args ) ;
124
118
} ;
125
- return {
126
- selectRef,
127
- mergedClassName,
128
- mode,
129
- focus,
119
+ expose ( {
130
120
blur,
131
- configProvider,
132
- triggerChange,
133
- prefixCls,
134
- } ;
135
- } ,
136
- render ( ) {
137
- const {
138
- configProvider,
139
- mode,
140
- mergedClassName,
141
- triggerChange,
142
- prefixCls,
143
- $slots : slots ,
144
- $props,
145
- } = this as any ;
146
- const props : SelectTypes = $props ;
147
- const {
148
- notFoundContent,
149
- listHeight = 256 ,
150
- listItemHeight = 24 ,
151
- getPopupContainer,
152
- dropdownClassName,
153
- direction,
154
- virtual,
155
- dropdownMatchSelectWidth,
156
- } = props ;
157
-
158
- const { renderEmpty, getPopupContainer : getContextPopupContainer } = configProvider ;
159
-
160
- const isMultiple = mode === 'multiple' || mode === 'tags' ;
161
-
162
- // ===================== Empty =====================
163
- let mergedNotFound : VNodeChild ;
164
- if ( notFoundContent !== undefined ) {
165
- mergedNotFound = notFoundContent ;
166
- } else if ( slots . notFoundContent ) {
167
- mergedNotFound = slots . notFoundContent ( ) ;
168
- } else if ( mode === 'combobox' ) {
169
- mergedNotFound = null ;
170
- } else {
171
- mergedNotFound = renderEmpty ( 'Select' ) as any ;
172
- }
173
-
174
- // ===================== Icons =====================
175
- const { suffixIcon, itemIcon, removeIcon, clearIcon } = getIcons (
176
- {
177
- ...this . $props ,
178
- multiple : isMultiple ,
179
- prefixCls,
180
- } ,
181
- slots ,
182
- ) ;
183
-
184
- const selectProps = omit ( props , [
185
- 'prefixCls' ,
186
- 'suffixIcon' ,
187
- 'itemIcon' ,
188
- 'removeIcon' ,
189
- 'clearIcon' ,
190
- 'size' ,
191
- 'bordered' ,
192
- ] ) as any ;
193
-
194
- const rcSelectRtlDropDownClassName = classNames ( dropdownClassName , {
195
- [ `${ prefixCls } -dropdown-${ direction } ` ] : direction === 'rtl' ,
121
+ focus,
196
122
} ) ;
197
- return (
198
- < RcSelect
199
- ref = "selectRef"
200
- virtual = { virtual }
201
- dropdownMatchSelectWidth = { dropdownMatchSelectWidth }
202
- { ...selectProps }
203
- { ...this . $attrs }
204
- listHeight = { listHeight }
205
- listItemHeight = { listItemHeight }
206
- mode = { mode }
207
- prefixCls = { prefixCls }
208
- direction = { direction }
209
- inputIcon = { suffixIcon }
210
- menuItemSelectedIcon = { itemIcon }
211
- removeIcon = { removeIcon }
212
- clearIcon = { clearIcon }
213
- notFoundContent = { mergedNotFound }
214
- class = { mergedClassName }
215
- getPopupContainer = { getPopupContainer || getContextPopupContainer }
216
- dropdownClassName = { rcSelectRtlDropDownClassName }
217
- onChange = { triggerChange }
218
- dropdownRender = { selectProps . dropdownRender || this . $slots . dropdownRender }
219
- >
220
- { slots . default ?.( ) }
221
- </ RcSelect >
222
- ) ;
123
+ return ( ) => {
124
+ const {
125
+ notFoundContent,
126
+ listHeight = 256 ,
127
+ listItemHeight = 24 ,
128
+ getPopupContainer,
129
+ dropdownClassName,
130
+ virtual,
131
+ dropdownMatchSelectWidth,
132
+ } = props ;
133
+
134
+ const { renderEmpty, getPopupContainer : getContextPopupContainer } = configProvider ;
135
+
136
+ const isMultiple = mode . value === 'multiple' || mode . value === 'tags' ;
137
+
138
+ // ===================== Empty =====================
139
+ let mergedNotFound : VNodeChild ;
140
+ if ( notFoundContent !== undefined ) {
141
+ mergedNotFound = notFoundContent ;
142
+ } else if ( slots . notFoundContent ) {
143
+ mergedNotFound = slots . notFoundContent ( ) ;
144
+ } else if ( mode . value === 'combobox' ) {
145
+ mergedNotFound = null ;
146
+ } else {
147
+ mergedNotFound = renderEmpty ( 'Select' ) as any ;
148
+ }
149
+
150
+ // ===================== Icons =====================
151
+ const { suffixIcon, itemIcon, removeIcon, clearIcon } = getIcons (
152
+ {
153
+ ...props ,
154
+ multiple : isMultiple ,
155
+ prefixCls : prefixCls . value ,
156
+ } ,
157
+ slots ,
158
+ ) ;
159
+
160
+ const selectProps = omit ( props , [
161
+ 'prefixCls' ,
162
+ 'suffixIcon' ,
163
+ 'itemIcon' ,
164
+ 'removeIcon' ,
165
+ 'clearIcon' ,
166
+ 'size' ,
167
+ 'bordered' ,
168
+ ] ) ;
169
+
170
+ const rcSelectRtlDropDownClassName = classNames ( dropdownClassName , {
171
+ [ `${ prefixCls . value } -dropdown-${ direction . value } ` ] : direction . value === 'rtl' ,
172
+ } ) ;
173
+ return (
174
+ < RcSelect
175
+ ref = { selectRef }
176
+ virtual = { virtual }
177
+ dropdownMatchSelectWidth = { dropdownMatchSelectWidth }
178
+ { ...selectProps }
179
+ { ...attrs }
180
+ listHeight = { listHeight }
181
+ listItemHeight = { listItemHeight }
182
+ mode = { mode . value }
183
+ prefixCls = { prefixCls . value }
184
+ direction = { direction . value }
185
+ inputIcon = { suffixIcon }
186
+ menuItemSelectedIcon = { itemIcon }
187
+ removeIcon = { removeIcon }
188
+ clearIcon = { clearIcon }
189
+ notFoundContent = { mergedNotFound }
190
+ class = { [ mergedClassName . value , attrs . class ] }
191
+ getPopupContainer = { getPopupContainer || getContextPopupContainer }
192
+ dropdownClassName = { rcSelectRtlDropDownClassName }
193
+ onChange = { triggerChange }
194
+ dropdownRender = { selectProps . dropdownRender || slots . dropdownRender }
195
+ >
196
+ { slots . default ?.( ) }
197
+ </ RcSelect >
198
+ ) ;
199
+ } ;
223
200
} ,
224
201
} ) ;
225
202
/* istanbul ignore next */
0 commit comments