mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Field): add clear-icon prop (#8438)
This commit is contained in:
parent
d51db70789
commit
2a065f85ef
@ -97,6 +97,10 @@ export default defineComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
clearIcon: {
|
||||||
|
type: String,
|
||||||
|
default: 'clear',
|
||||||
|
},
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: '',
|
default: '',
|
||||||
@ -546,7 +550,11 @@ export default defineComponent({
|
|||||||
<div class={bem('body')}>
|
<div class={bem('body')}>
|
||||||
{renderInput()}
|
{renderInput()}
|
||||||
{showClear.value && (
|
{showClear.value && (
|
||||||
<Icon name="clear" class={bem('clear')} onTouchstart={onClear} />
|
<Icon
|
||||||
|
name={props.clearIcon}
|
||||||
|
class={bem('clear')}
|
||||||
|
onTouchstart={onClear}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{renderRightIcon()}
|
{renderRightIcon()}
|
||||||
{slots.button && <div class={bem('button')}>{slots.button()}</div>}
|
{slots.button && <div class={bem('button')}>{slots.button()}</div>}
|
||||||
|
@ -265,6 +265,7 @@ Use `input-align` prop to align the input value.
|
|||||||
| autosize | Textarea auto resize,can accpet an object,<br>e.g. { maxHeight: 100, minHeight: 50 } | _boolean \| object_ | `false` |
|
| autosize | Textarea auto resize,can accpet an object,<br>e.g. { maxHeight: 100, minHeight: 50 } | _boolean \| object_ | `false` |
|
||||||
| left-icon | Left side icon name | _string_ | - |
|
| left-icon | Left side icon name | _string_ | - |
|
||||||
| right-icon | Right side icon name | _string_ | - |
|
| right-icon | Right side icon name | _string_ | - |
|
||||||
|
| clear-icon `v3.0.12` | Clear icon name | _string_ | `clear` |
|
||||||
| icon-prefix | Icon className prefix | _string_ | `van-icon` |
|
| icon-prefix | Icon className prefix | _string_ | `van-icon` |
|
||||||
| rules | Form validation rules | _Rule[]_ | - |
|
| rules | Form validation rules | _Rule[]_ | - |
|
||||||
| autocomplete `v3.0.3` | [autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) attribute of native input element | _string_ | - |
|
| autocomplete `v3.0.3` | [autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) attribute of native input element | _string_ | - |
|
||||||
|
@ -288,6 +288,7 @@ export default {
|
|||||||
| autosize | 是否自适应内容高度,只对 textarea 有效,<br>可传入对象,如 { maxHeight: 100, minHeight: 50 },<br>单位为`px` | _boolean \| object_ | `false` |
|
| autosize | 是否自适应内容高度,只对 textarea 有效,<br>可传入对象,如 { maxHeight: 100, minHeight: 50 },<br>单位为`px` | _boolean \| object_ | `false` |
|
||||||
| left-icon | 左侧[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - |
|
| left-icon | 左侧[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - |
|
||||||
| right-icon | 右侧[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - |
|
| right-icon | 右侧[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - |
|
||||||
|
| clear-icon `v3.0.12` | 清除[图标名称](#/zh-CN/icon)或图片链接 | _string_ | `clear` |
|
||||||
| icon-prefix | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
| icon-prefix | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
||||||
| rules | 表单校验规则,详见 [Form 组件](#/zh-CN/form#rule-shu-ju-jie-gou) | _Rule[]_ | - |
|
| rules | 表单校验规则,详见 [Form 组件](#/zh-CN/form#rule-shu-ju-jie-gou) | _Rule[]_ | - |
|
||||||
| autocomplete `v3.0.3` | input 标签原生的[自动完成属性](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) | _string_ | - |
|
| autocomplete `v3.0.3` | input 标签原生的[自动完成属性](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) | _string_ | - |
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`should change clear icon when using clear-icon prop 1`] = `
|
||||||
|
<i class="van-badge__wrapper van-icon van-icon-cross van-field__clear">
|
||||||
|
</i>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`should render colon when using colon prop 1`] = `
|
exports[`should render colon when using colon prop 1`] = `
|
||||||
<div class="van-cell__title van-field__label">
|
<div class="van-cell__title van-field__label">
|
||||||
<span>
|
<span>
|
||||||
|
@ -430,3 +430,17 @@ test('should allow to set autocomplete attribute', () => {
|
|||||||
'on'
|
'on'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should change clear icon when using clear-icon prop', async () => {
|
||||||
|
const wrapper = mount(Field, {
|
||||||
|
props: {
|
||||||
|
clearable: true,
|
||||||
|
clearIcon: 'cross',
|
||||||
|
modelValue: 'test',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const input = wrapper.find('input');
|
||||||
|
await input.trigger('focus');
|
||||||
|
expect(wrapper.find('.van-field__clear').html()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user