fix(cascader): remove disabled from filtered options

This commit is contained in:
songwanli2025@163.com 2020-02-18 18:57:12 +08:00
parent 0de9b9c137
commit 181b42ac45
2 changed files with 6 additions and 4 deletions

View File

@ -100,6 +100,7 @@ export default {
(type !== 'multiple' && type !== 'single')
) {
if (option.isRoot) return
if (option.disabled) return
selectOptions.push({
label: option.path.map(optionInPath => optionInPath.label).join('/'),
value: option.value,

View File

@ -334,7 +334,7 @@ function linkedCascaderOptions (options, type) {
function menuOptions (cascaderOptions, value, type) {
const valueSet = new Set(value)
function traverse (options) {
function traverse (options, parentDisabled = false) {
if (!Array.isArray(options)) return
const length = options.length
for (let i = 0; i < length; ++i) {
@ -342,10 +342,11 @@ function menuOptions (cascaderOptions, value, type) {
option.checkedLeafCount = 0
option.checkedAvailableLeafCount = 0
option.hasCheckedLeaf = false
option.disabled = parentDisabled || option.disabled
if (type === 'multiple') {
if (option.loaded) {
if (!option.isLeaf) {
traverse(option.children)
traverse(option.children, option.disabled)
option.children.forEach(child => {
option.checkedLeafCount += child.checkedLeafCount
option.checkedAvailableLeafCount += child.checkedAvailableLeafCount
@ -369,14 +370,14 @@ function menuOptions (cascaderOptions, value, type) {
}
} else if (type === 'multiple-all-options') {
if (option.loaded && !option.isLeaf) {
traverse(option.children)
traverse(option.children, option.disabled)
} else {
option.checkedLeafCount = NaN
}
option.checked = valueSet.has(option.value)
} else if (type === 'single' || type === 'single-all-options') {
if (hasChildren(option)) {
traverse(option.children)
traverse(option.children, option.disabled)
}
option.checked = (option.value === value)
}