Skip to content

Commit 435b8a1

Browse files
committed
feat: update vc-select
1 parent e706170 commit 435b8a1

File tree

9 files changed

+386
-235
lines changed

9 files changed

+386
-235
lines changed

components/_util/props-util.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ const getSlots = (ele) => {
5252
const children = ele.children || componentOptions.children || []
5353
const slots = {}
5454
children.forEach(child => {
55-
const name = (child.data && child.data.slot) || 'default'
56-
slots[name] = slots[name] || []
57-
slots[name].push(child)
55+
if (!isEmptyElement(child)) {
56+
const name = (child.data && child.data.slot) || 'default'
57+
slots[name] = slots[name] || []
58+
slots[name].push(child)
59+
}
5860
})
5961
return slots
6062
}
@@ -213,12 +215,12 @@ export function getComponentName (opts) {
213215
return opts && (opts.Ctor.options.name || opts.tag)
214216
}
215217

216-
export function isEmptyElement (ele) {
217-
return !(ele.tag || ele.text.trim() !== '')
218+
export function isEmptyElement (c) {
219+
return !(c.tag || (c.text && c.text.trim() !== ''))
218220
}
219221

220222
export function filterEmpty (children = []) {
221-
return children.filter(c => c.tag || (c.text && c.text.trim() !== ''))
223+
return children.filter(c => !isEmptyElement(c))
222224
}
223225
const initDefaultProps = (propTypes, defaultProps) => {
224226
Object.keys(defaultProps).forEach(k => {

components/vc-select/DropdownMenu.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
name: 'DropdownMenu',
1212
mixins: [BaseMixin],
1313
props: {
14+
ariaId: PropTypes.string,
1415
defaultActiveFirstOption: PropTypes.bool,
1516
value: PropTypes.any,
1617
dropdownMenuStyle: PropTypes.object,
@@ -28,8 +29,10 @@ export default {
2829
menuItemSelectedIcon: PropTypes.any,
2930
},
3031

31-
beforeMount () {
32+
created () {
33+
this.rafInstance = { cancel: () => null }
3234
this.lastInputValue = this.$props.inputValue
35+
this.lastVisible = false
3336
},
3437

3538
mounted () {
@@ -101,6 +104,7 @@ export default {
101104
firstActiveValue,
102105
dropdownMenuStyle,
103106
backfillValue,
107+
visible,
104108
} = props
105109
const menuItemSelectedIcon = getComponentFromProp(this, 'menuItemSelectedIcon')
106110
const { menuDeselect, menuSelect, popupScroll } = this.$listeners
@@ -136,16 +140,16 @@ export default {
136140
if (selectedKeys.length || firstActiveValue) {
137141
if (props.visible && !this.lastVisible) {
138142
activeKeyProps.activeKey = selectedKeys[0] !== undefined ? selectedKeys[0] : firstActiveValue
143+
} else if (!visible) {
144+
activeKeyProps.activeKey = undefined
139145
}
140146
let foundFirst = false
141147
// set firstActiveItem via cloning menus
142148
// for scroll into view
143149
const clone = item => {
144150
if (
145151
(!foundFirst && selectedKeys.indexOf(item.key) !== -1) ||
146-
(!foundFirst &&
147-
!selectedKeys.length &&
148-
firstActiveValue.indexOf(item.key) !== -1)
152+
(!foundFirst && !selectedKeys.length && firstActiveValue.indexOf(item.key) !== -1)
149153
) {
150154
foundFirst = true
151155
return cloneElement(item, {
@@ -198,6 +202,8 @@ export default {
198202
overflow: 'auto',
199203
transform: 'translateZ(0)',
200204
}}
205+
id={this.$props.ariaId}
206+
tabIndex='-1'
201207
onFocus={popupFocus}
202208
onMousedown={preventDefaultEvent}
203209
onScroll={popupScroll}

components/vc-select/OptGroup.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
import PropTypes from '../_util/vue-types'
33
export default {
44
props: {
5-
label: PropTypes.any,
5+
value: PropTypes.oneOfType([
6+
PropTypes.string,
7+
PropTypes.number,
8+
]),
9+
label: PropTypes.oneOfType([
10+
PropTypes.string,
11+
PropTypes.number,
12+
]),
613
},
714
isSelectOptGroup: true,
815
}

components/vc-select/Option.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export default {
77
PropTypes.string,
88
PropTypes.number,
99
]),
10+
label: PropTypes.oneOfType([
11+
PropTypes.string,
12+
PropTypes.number,
13+
]),
1014
disabled: PropTypes.bool,
11-
title: PropTypes.string,
15+
title: PropTypes.oneOfType([
16+
PropTypes.string,
17+
PropTypes.number,
18+
]),
1219
},
1320
isSelectOption: true,
1421
}

components/vc-select/PropTypes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const SelectPropTypes = {
3131
placeholder: PropTypes.any,
3232
// onDeselect: PropTypes.func,
3333
labelInValue: PropTypes.bool,
34+
loading: PropTypes.bool,
3435
value: PropTypes.any,
3536
defaultValue: PropTypes.any,
3637
dropdownStyle: PropTypes.object,
@@ -47,4 +48,12 @@ export const SelectPropTypes = {
4748
inputIcon: PropTypes.any,
4849
removeIcon: PropTypes.any,
4950
menuItemSelectedIcon: PropTypes.any,
51+
dropdownRender: PropTypes.func,
52+
mode: PropTypes.oneOf(['multiple', 'tags']),
53+
backfill: PropTypes.bool,
54+
dropdownAlign: PropTypes.any,
55+
dropdownMatchSelectWidth: PropTypes.bool,
56+
dropdownMenuStyle: PropTypes.object,
57+
notFoundContent: PropTypes.oneOfType([String, Number]),
58+
tabIndex: PropTypes.oneOfType([String, Number]),
5059
}

0 commit comments

Comments
 (0)