mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-18 12:34:25 +08:00
feat(transfer): default-value prop
This commit is contained in:
parent
dd0e8f16ff
commit
61c74779d2
@ -13,12 +13,11 @@ size
|
|||||||
filterable
|
filterable
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- -->
|
|
||||||
|
|
||||||
## Props
|
## Props
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
| default-value | `Array<string \| number> \| null` | `null` | |
|
||||||
| disabled | `boolean` | `true` | |
|
| disabled | `boolean` | `true` | |
|
||||||
| filterable | `boolean` | `false` | |
|
| filterable | `boolean` | `false` | |
|
||||||
| filter | `(pattern: string, option: TransferOption, from: 'source' \| 'target') => boolean` | A basic label string match function | |
|
| filter | `(pattern: string, option: TransferOption, from: 'source' \| 'target') => boolean` | A basic label string match function | |
|
||||||
@ -29,7 +28,7 @@ filterable
|
|||||||
| target-filter-placeholder | `string` | `undefined` | |
|
| target-filter-placeholder | `string` | `undefined` | |
|
||||||
| target-title | `string` | `'Target'` | |
|
| target-title | `string` | `'Target'` | |
|
||||||
| theme | `'light' \| 'dark' \| string` | `undefined` | |
|
| theme | `'light' \| 'dark' \| string` | `undefined` | |
|
||||||
| value | `Array<string \| number>` | `null` | |
|
| value | `Array<string \| number> \| null` | `undefined` | |
|
||||||
| on-update:value | `(value: Array<string \| number>) => any` | `undefined` | |
|
| on-update:value | `(value: Array<string \| number>) => any` | `undefined` | |
|
||||||
| virtual-scroll | `boolean` | `false` | If use virtual scroll on transfer. If set to `true` it can handles large data (and turn transfer animation off) |
|
| virtual-scroll | `boolean` | `false` | If use virtual scroll on transfer. If set to `true` it can handles large data (and turn transfer animation off) |
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ filterable
|
|||||||
|
|
||||||
| 名称 | 类型 | 默认值 | 说明 |
|
| 名称 | 类型 | 默认值 | 说明 |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
| default-value | `Array<string \| number> \| null` | `null` | |
|
||||||
| disabled | `boolean` | `true` | |
|
| disabled | `boolean` | `true` | |
|
||||||
| filterable | `boolean` | `false` | |
|
| filterable | `boolean` | `false` | |
|
||||||
| filter | `(pattern: string, option: TransferOption, from: 'source' \| 'target') => boolean` | 一个简单的标签字符串匹配函数 | |
|
| filter | `(pattern: string, option: TransferOption, from: 'source' \| 'target') => boolean` | 一个简单的标签字符串匹配函数 | |
|
||||||
@ -27,7 +28,7 @@ filterable
|
|||||||
| target-filter-placeholder | `string` | `undefined` | |
|
| target-filter-placeholder | `string` | `undefined` | |
|
||||||
| target-title | `string` | `'目标项'` | |
|
| target-title | `string` | `'目标项'` | |
|
||||||
| theme | `'light' \| 'dark' \| string` | `undefined` | |
|
| theme | `'light' \| 'dark' \| string` | `undefined` | |
|
||||||
| value | `Array<string \| number>` | `null` | |
|
| value | `Array<string \| number> \| null` | `undefined` | |
|
||||||
| on-update:value | `(value: Array<string \| number>) => any` | `undefined` | |
|
| on-update:value | `(value: Array<string \| number>) => any` | `undefined` | |
|
||||||
| virtual-scroll | `boolean` | `false` | If use virtual scroll on transfer. If set to `true` it can handles large data (and turn transfer animation off) |
|
| virtual-scroll | `boolean` | `false` | If use virtual scroll on transfer. If set to `true` it can handles large data (and turn transfer animation off) |
|
||||||
|
|
||||||
|
@ -260,6 +260,10 @@ export default {
|
|||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
|
type: Array,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
|
defaultValue: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
@ -346,15 +350,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
doUpdateValue (...args) {
|
doUpdateValue (value) {
|
||||||
const {
|
const {
|
||||||
'onUpdate:value': onUpdateValue,
|
'onUpdate:value': onUpdateValue,
|
||||||
onChange,
|
onChange,
|
||||||
nTriggerFormInput,
|
nTriggerFormInput,
|
||||||
nTriggerFormChange
|
nTriggerFormChange
|
||||||
} = this
|
} = this
|
||||||
if (onUpdateValue) call(onUpdateValue, ...args)
|
if (onUpdateValue) call(onUpdateValue, value)
|
||||||
if (onChange) call(onChange, ...args)
|
if (onChange) call(onChange, value)
|
||||||
|
this.uncontrolledValue = value
|
||||||
nTriggerFormInput()
|
nTriggerFormInput()
|
||||||
nTriggerFormChange()
|
nTriggerFormChange()
|
||||||
},
|
},
|
||||||
@ -399,13 +404,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleToTgtClick () {
|
handleToTgtClick () {
|
||||||
this.doUpdateValue(this.srcCheckedValues.concat(this.value || []))
|
this.doUpdateValue(this.srcCheckedValues.concat(this.mergedValue || []))
|
||||||
this.srcCheckedValues = []
|
this.srcCheckedValues = []
|
||||||
},
|
},
|
||||||
handleToSrcClick () {
|
handleToSrcClick () {
|
||||||
const tgtCheckedValueSet = new Set(this.tgtCheckedValues)
|
const tgtCheckedValueSet = new Set(this.tgtCheckedValues)
|
||||||
this.doUpdateValue(
|
this.doUpdateValue(
|
||||||
(this.value || []).filter((v) => !tgtCheckedValueSet.has(v))
|
(this.mergedValue || []).filter((v) => !tgtCheckedValueSet.has(v))
|
||||||
)
|
)
|
||||||
this.tgtCheckedValues = []
|
this.tgtCheckedValues = []
|
||||||
},
|
},
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
import { ref, computed } from 'vue'
|
import { ref, computed, toRef } from 'vue'
|
||||||
import { useMemo } from 'vooks'
|
import { useMemo, useMergedState } from 'vooks'
|
||||||
|
|
||||||
export function data (props) {
|
export function data (props) {
|
||||||
|
const uncontrolledValueRef = ref(props.defaultValue)
|
||||||
|
const controlledValueRef = toRef(props, 'value')
|
||||||
|
const mergedValueRef = useMergedState(
|
||||||
|
controlledValueRef,
|
||||||
|
uncontrolledValueRef
|
||||||
|
)
|
||||||
const optMapRef = computed(() => {
|
const optMapRef = computed(() => {
|
||||||
const map = new Map()
|
const map = new Map()
|
||||||
;(props.options || []).forEach((opt) => map.set(opt.value, opt))
|
;(props.options || []).forEach((opt) => map.set(opt.value, opt))
|
||||||
return map
|
return map
|
||||||
})
|
})
|
||||||
const tgtValueSetRef = computed(() => new Set(props.value || []))
|
const tgtValueSetRef = computed(() => new Set(mergedValueRef.value || []))
|
||||||
const srcOptsRef = computed(() =>
|
const srcOptsRef = computed(() =>
|
||||||
props.options.filter((option) => !tgtValueSetRef.value.has(option.value))
|
props.options.filter((option) => !tgtValueSetRef.value.has(option.value))
|
||||||
)
|
)
|
||||||
const tgtOptsRef = computed(() => {
|
const tgtOptsRef = computed(() => {
|
||||||
const optMap = optMapRef.value
|
const optMap = optMapRef.value
|
||||||
return (props.value || []).map((v) => optMap.get(v))
|
return (mergedValueRef.value || []).map((v) => optMap.get(v))
|
||||||
})
|
})
|
||||||
const srcPatternRef = ref('')
|
const srcPatternRef = ref('')
|
||||||
const tgtPatternRef = ref('')
|
const tgtPatternRef = ref('')
|
||||||
@ -121,6 +127,8 @@ export function data (props) {
|
|||||||
isInputingRef.value = false
|
isInputingRef.value = false
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
uncontrolledValue: uncontrolledValueRef,
|
||||||
|
mergedValue: mergedValueRef,
|
||||||
avlSrcValueSet: avlSrcValueSetRef,
|
avlSrcValueSet: avlSrcValueSetRef,
|
||||||
avlTgtValueSet: avlTgtValueSetRef,
|
avlTgtValueSet: avlTgtValueSetRef,
|
||||||
tgtOpts: tgtOptsRef,
|
tgtOpts: tgtOptsRef,
|
||||||
|
2
vue3.md
2
vue3.md
@ -303,6 +303,8 @@
|
|||||||
- `v-model` => `v-model:value`
|
- `v-model` => `v-model:value`
|
||||||
- deprecate
|
- deprecate
|
||||||
- `on-change` => `on-update:value`
|
- `on-change` => `on-update:value`
|
||||||
|
- new
|
||||||
|
- `default-value` prop
|
||||||
- [x] tree
|
- [x] tree
|
||||||
- break
|
- break
|
||||||
- `v-model` => `v-model:selected-keys`
|
- `v-model` => `v-model:selected-keys`
|
||||||
|
Loading…
Reference in New Issue
Block a user