mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Cell): add tag prop (#11139)
This commit is contained in:
parent
564d751fd8
commit
2729ebff85
@ -12,6 +12,7 @@ import {
|
|||||||
truthProp,
|
truthProp,
|
||||||
unknownProp,
|
unknownProp,
|
||||||
numericProp,
|
numericProp,
|
||||||
|
makeStringProp,
|
||||||
createNamespace,
|
createNamespace,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ export type CellSize = 'normal' | 'large';
|
|||||||
export type CellArrowDirection = 'up' | 'down' | 'left' | 'right';
|
export type CellArrowDirection = 'up' | 'down' | 'left' | 'right';
|
||||||
|
|
||||||
export const cellSharedProps = {
|
export const cellSharedProps = {
|
||||||
|
tag: makeStringProp<keyof HTMLElementTagNameMap>('div'),
|
||||||
icon: String,
|
icon: String,
|
||||||
size: String as PropType<CellSize>,
|
size: String as PropType<CellSize>,
|
||||||
title: numericProp,
|
title: numericProp,
|
||||||
@ -131,7 +133,7 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const { size, center, border, isLink, required } = props;
|
const { tag, size, center, border, isLink, required } = props;
|
||||||
const clickable = props.clickable ?? isLink;
|
const clickable = props.clickable ?? isLink;
|
||||||
|
|
||||||
const classes: Record<string, boolean | undefined> = {
|
const classes: Record<string, boolean | undefined> = {
|
||||||
@ -145,7 +147,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<tag
|
||||||
class={bem(classes)}
|
class={bem(classes)}
|
||||||
role={clickable ? 'button' : undefined}
|
role={clickable ? 'button' : undefined}
|
||||||
tabindex={clickable ? 0 : undefined}
|
tabindex={clickable ? 0 : undefined}
|
||||||
@ -156,7 +158,7 @@ export default defineComponent({
|
|||||||
{renderValue()}
|
{renderValue()}
|
||||||
{renderRightIcon()}
|
{renderRightIcon()}
|
||||||
{slots.extra?.()}
|
{slots.extra?.()}
|
||||||
</div>
|
</tag>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -154,11 +154,12 @@ app.use(CellGroup);
|
|||||||
| size | Size, can be set to `large` | _string_ | - |
|
| size | Size, can be set to `large` | _string_ | - |
|
||||||
| icon | Left Icon | _string_ | - |
|
| icon | Left Icon | _string_ | - |
|
||||||
| icon-prefix | Icon className prefix | _string_ | `van-icon` |
|
| icon-prefix | Icon className prefix | _string_ | `van-icon` |
|
||||||
| border | Whether to show inner border | _boolean_ | `true` |
|
| tag | Custom element tag | _string_ | `div` |
|
||||||
| center | Whether to center content vertically | _boolean_ | `false` |
|
|
||||||
| url | Link URL | _string_ | - |
|
| url | Link URL | _string_ | - |
|
||||||
| to | Target route of the link, same as to of vue-router | _string \| object_ | - |
|
| to | Target route of the link, same as to of vue-router | _string \| object_ | - |
|
||||||
| replace | If true, the navigation will not leave a history record | _boolean_ | `false` |
|
| replace | If true, the navigation will not leave a history record | _boolean_ | `false` |
|
||||||
|
| border | Whether to show inner border | _boolean_ | `true` |
|
||||||
|
| center | Whether to center content vertically | _boolean_ | `false` |
|
||||||
| clickable | Whether to show click feedback when clicked | _boolean_ | `null` |
|
| clickable | Whether to show click feedback when clicked | _boolean_ | `null` |
|
||||||
| is-link | Whether to show link icon | _boolean_ | `false` |
|
| is-link | Whether to show link icon | _boolean_ | `false` |
|
||||||
| required | Whether to show required mark | _boolean_ | `false` |
|
| required | Whether to show required mark | _boolean_ | `false` |
|
||||||
|
@ -159,6 +159,7 @@ app.use(CellGroup);
|
|||||||
| size | 单元格大小,可选值为 `large` | _string_ | - |
|
| size | 单元格大小,可选值为 `large` | _string_ | - |
|
||||||
| icon | 左侧图标名称或图片链接,等同于 Icon 组件的 [name 属性](#/zh-CN/icon#props) | _string_ | - |
|
| icon | 左侧图标名称或图片链接,等同于 Icon 组件的 [name 属性](#/zh-CN/icon#props) | _string_ | - |
|
||||||
| icon-prefix | 图标类名前缀,等同于 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
| icon-prefix | 图标类名前缀,等同于 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
||||||
|
| tag | 根节点对应的 HTML 标签名 | _string_ | `div` |
|
||||||
| url | 点击后跳转的链接地址 | _string_ | - |
|
| url | 点击后跳转的链接地址 | _string_ | - |
|
||||||
| to | 点击后跳转的目标路由对象,等同于 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | _string \| object_ | - |
|
| to | 点击后跳转的目标路由对象,等同于 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | _string \| object_ | - |
|
||||||
| border | 是否显示内边框 | _boolean_ | `true` |
|
| border | 是否显示内边框 | _boolean_ | `true` |
|
||||||
|
@ -37,6 +37,11 @@ exports[`should render label slot correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`should render tag prop correctly 1`] = `
|
||||||
|
<a class="van-cell">
|
||||||
|
</a>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`should render title slot correctly 1`] = `
|
exports[`should render title slot correctly 1`] = `
|
||||||
<div class="van-cell">
|
<div class="van-cell">
|
||||||
<div class="van-cell__title">
|
<div class="van-cell__title">
|
||||||
|
@ -85,7 +85,7 @@ test('should change icon class prefix when using icon-prefix prop', () => {
|
|||||||
expect(wrapper.html()).toMatchSnapshot();
|
expect(wrapper.html()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should allow to disable clicakble when using is-link prop', () => {
|
test('should allow to disable clickable when using is-link prop', () => {
|
||||||
const wrapper = mount(Cell, {
|
const wrapper = mount(Cell, {
|
||||||
props: {
|
props: {
|
||||||
isLink: true,
|
isLink: true,
|
||||||
@ -94,3 +94,12 @@ test('should allow to disable clicakble when using is-link prop', () => {
|
|||||||
});
|
});
|
||||||
expect(wrapper.classes()).not.toContain('van-cell--clickable');
|
expect(wrapper.classes()).not.toContain('van-cell--clickable');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should render tag prop correctly', () => {
|
||||||
|
const wrapper = mount(Cell, {
|
||||||
|
props: {
|
||||||
|
tag: 'a',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(wrapper.html()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user