mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-03-07 13:48:31 +08:00
refactor(auto-complete): getDerivedShowFromValue => getShow
This commit is contained in:
parent
c523e27cf4
commit
497e657013
@ -11,7 +11,7 @@
|
||||
|
||||
### Feats
|
||||
|
||||
- `n-auto-complete` add `get-derived-show-from-value` prop, closes [#1292](https://github.com/TuSimple/naive-ui/issues/1292).
|
||||
- `n-auto-complete` add `get-show` prop, closes [#1292](https://github.com/TuSimple/naive-ui/issues/1292).
|
||||
- `n-select` add `input-props` prop, closes [#1351](https://github.com/TuSimple/naive-ui/issues/1351).
|
||||
- `n-color-picker` add `swatches` prop, ref [#1281](https://github.com/TuSimple/naive-ui/issues/1281).
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
### Feats
|
||||
|
||||
- `n-auto-complete` 新增 `get-derived-show-from-value` 属性,关闭 [#1292](https://github.com/TuSimple/naive-ui/issues/1292)
|
||||
- `n-auto-complete` 新增 `get-show` 属性,关闭 [#1292](https://github.com/TuSimple/naive-ui/issues/1292)
|
||||
- `n-select` 新增 `input-props` 属性,关闭 [#1351](https://github.com/TuSimple/naive-ui/issues/1351)
|
||||
- `n-color-picker` 新增 `swatches` 属性,有关 [#1281](https://github.com/TuSimple/naive-ui/issues/1281)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Actions After Select
|
||||
# Actions after select
|
||||
|
||||
Choose whether the element blurs after a selection is made with `blur-after-select`.
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Custom Input Element
|
||||
# Custom input element
|
||||
|
||||
You can also replace the input element of the auto-complete component.
|
||||
|
||||
|
@ -24,7 +24,7 @@ show-options-by-value
|
||||
| clearable | `boolean` | `false` | Whether auto complete is clearable. |
|
||||
| default-value | `string` | `null` | Default value of auto complete. |
|
||||
| disabled | `boolean` | `false` | Whether the auto complete is disabled. |
|
||||
| getDerivedShowFromValue | `(inputValue: string \| null) => boolean` | `undefined` | Based on value to determine is Whether to show all options when focusing. |
|
||||
| get-show | `(value: string \| null) => boolean` | `undefined` | Based on value to determine whether to show menu when focusing. |
|
||||
| loading | `boolean` | `false` | Whether to show a loading status. |
|
||||
| options | `Array<string \| AutoCompleteOption \| AutoCompleteGroupOption>` | `[]` | Auto complete options. |
|
||||
| placeholder | `string` | `'Please Input'` | Auto complete's placeholder. |
|
||||
|
@ -1,13 +1,13 @@
|
||||
# Whether to show all options
|
||||
# Whether to show menu
|
||||
|
||||
Your can determine is whether to show all options based on value when it is focused.
|
||||
Your can determine is whether to show menu based on value when it is focused.
|
||||
|
||||
```html
|
||||
<n-auto-complete
|
||||
:options="options"
|
||||
v-model:value="value"
|
||||
placeholder="input empty or not `a` value to show all options"
|
||||
:get-derived-show-from-value="getDerivedShowFromValue"
|
||||
placeholder="Input 'a' to show menu"
|
||||
:get-show="getShow"
|
||||
/>
|
||||
```
|
||||
|
||||
@ -30,8 +30,8 @@ export default defineComponent({
|
||||
})
|
||||
}),
|
||||
showOnFocus: showOnFocusRef,
|
||||
getDerivedShowFromValue: (value) => {
|
||||
if (!value || value !== 'a') {
|
||||
getShow: (value) => {
|
||||
if (value === 'a') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -24,7 +24,7 @@ show-options-by-value
|
||||
| clearable | `boolean` | `false` | 自动填充是否支持可清除 |
|
||||
| default-value | `string` | `null` | 自动填充的默认值 |
|
||||
| disabled | `boolean` | `false` | 自动填充是否禁用 |
|
||||
| getDerivedShowFromValue | `(inputValue: string \| null) => boolean` | `undefined` | 根据输入值决定是否显示所有选项 |
|
||||
| get-show | `(value: string \| null) => boolean` | `undefined` | 根据输入值在聚焦的状态中决定是否显示菜单 |
|
||||
| loading | `boolean` | `false` | 是否展示加载状态 |
|
||||
| options | `Array<string \| AutoCompleteOption \| AutoCompleteGroupOption>` | `[]` | 自动填充的自定义选项 |
|
||||
| placeholder | `string` | `'请输入'` | 自动填充的提示信息 |
|
||||
|
@ -1,13 +1,13 @@
|
||||
# 是否显示所有选项
|
||||
# 是否显示菜单
|
||||
|
||||
你可以根据输入的值来决定是否显示所有选项
|
||||
你可以根据输入的值来决定是否显示菜单
|
||||
|
||||
```html
|
||||
<n-auto-complete
|
||||
:options="options"
|
||||
v-model:value="value"
|
||||
placeholder="输入空或者非`a`显示所有选项"
|
||||
:get-derived-show-from-value="getDerivedShowFromValue"
|
||||
placeholder="输入 a 显示菜单"
|
||||
:get-show="getShow"
|
||||
/>
|
||||
```
|
||||
|
||||
@ -30,8 +30,8 @@ export default defineComponent({
|
||||
})
|
||||
}),
|
||||
showOnFocus: showOnFocusRef,
|
||||
getDerivedShowFromValue: (value) => {
|
||||
if (!value || value !== 'a') {
|
||||
getShow: (value) => {
|
||||
if (value === 'a') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -70,9 +70,7 @@ const autoCompleteProps = {
|
||||
value: String,
|
||||
blurAfterSelect: Boolean,
|
||||
clearAfterSelect: Boolean,
|
||||
getDerivedShowFromValue: Function as PropType<
|
||||
(inputValue: string | null) => boolean
|
||||
>,
|
||||
getShow: Function as PropType<(inputValue: string | null) => boolean>,
|
||||
size: String as PropType<'small' | 'medium' | 'large'>,
|
||||
options: {
|
||||
type: Array as PropType<AutoCompleteOptions>,
|
||||
@ -134,8 +132,10 @@ export default defineComponent({
|
||||
return mapAutoCompleteOptionsToSelectOptions(props.options)
|
||||
})
|
||||
const mergedShowOptionsRef = computed(() => {
|
||||
const { getDerivedShowFromValue } = props
|
||||
if (getDerivedShowFromValue) { return getDerivedShowFromValue(mergedValueRef.value) }
|
||||
const { getShow } = props
|
||||
if (getShow) {
|
||||
return getShow(mergedValueRef.value)
|
||||
}
|
||||
return !!mergedValueRef.value
|
||||
})
|
||||
const activeRef = computed(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user