mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(nav-bar): add clickable prop to nav-bar component (#11048)
* feat: add clickable prop to nav-bar * test(nav-bar): add clickable prop test case
This commit is contained in:
parent
9f2eb92172
commit
ea0ba1fcf1
@ -33,6 +33,7 @@ export const navBarProps = {
|
|||||||
leftArrow: Boolean,
|
leftArrow: Boolean,
|
||||||
placeholder: Boolean,
|
placeholder: Boolean,
|
||||||
safeAreaInsetTop: Boolean,
|
safeAreaInsetTop: Boolean,
|
||||||
|
clickable: truthProp,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NavBarProps = ExtractPropTypes<typeof navBarProps>;
|
export type NavBarProps = ExtractPropTypes<typeof navBarProps>;
|
||||||
@ -92,7 +93,7 @@ export default defineComponent({
|
|||||||
<div class={bem('content')}>
|
<div class={bem('content')}>
|
||||||
{hasLeft && (
|
{hasLeft && (
|
||||||
<div
|
<div
|
||||||
class={[bem('left'), HAPTICS_FEEDBACK]}
|
class={[bem('left'), props.clickable ? HAPTICS_FEEDBACK : '']}
|
||||||
onClick={onClickLeft}
|
onClick={onClickLeft}
|
||||||
>
|
>
|
||||||
{renderLeft()}
|
{renderLeft()}
|
||||||
@ -103,7 +104,7 @@ export default defineComponent({
|
|||||||
</div>
|
</div>
|
||||||
{hasRight && (
|
{hasRight && (
|
||||||
<div
|
<div
|
||||||
class={[bem('right'), HAPTICS_FEEDBACK]}
|
class={[bem('right'), props.clickable ? HAPTICS_FEEDBACK : '']}
|
||||||
onClick={onClickRight}
|
onClick={onClickRight}
|
||||||
>
|
>
|
||||||
{renderRight()}
|
{renderRight()}
|
||||||
|
@ -99,6 +99,7 @@ export default {
|
|||||||
| placeholder | Whether to generate a placeholder element when fixed | _boolean_ | `false` |
|
| placeholder | Whether to generate a placeholder element when fixed | _boolean_ | `false` |
|
||||||
| z-index | Z-index | _number \| string_ | `1` |
|
| z-index | Z-index | _number \| string_ | `1` |
|
||||||
| safe-area-inset-top | Whether to enable top safe area adaptation | _boolean_ | `false` |
|
| safe-area-inset-top | Whether to enable top safe area adaptation | _boolean_ | `false` |
|
||||||
|
| clickable | Whether to add `van-haptics-feedback` class name to parent element when render `Slots` | _boolean_ | `true` |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ export default {
|
|||||||
### Props
|
### Props
|
||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- |
|
||||||
| title | 标题 | _string_ | `''` |
|
| title | 标题 | _string_ | `''` |
|
||||||
| left-text | 左侧文案 | _string_ | `''` |
|
| left-text | 左侧文案 | _string_ | `''` |
|
||||||
| right-text | 右侧文案 | _string_ | `''` |
|
| right-text | 右侧文案 | _string_ | `''` |
|
||||||
@ -107,6 +107,7 @@ export default {
|
|||||||
| placeholder | 固定在顶部时,是否在标签位置生成一个等高的占位元素 | _boolean_ | `false` |
|
| placeholder | 固定在顶部时,是否在标签位置生成一个等高的占位元素 | _boolean_ | `false` |
|
||||||
| z-index | 导航栏 z-index | _number \| string_ | `1` |
|
| z-index | 导航栏 z-index | _number \| string_ | `1` |
|
||||||
| safe-area-inset-top | 是否开启[顶部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `false` |
|
| safe-area-inset-top | 是否开启[顶部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `false` |
|
||||||
|
| clickable | 渲染 `Slots` 是否在父元素添加 `van-haptics-feedback` 类名 | _boolean_ | `true` | |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
@ -25,6 +25,18 @@ exports[`should render placeholder element when using placeholder prop 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`should render slots correctly when set clickable to false 1`] = `
|
||||||
|
<div class="van-nav-bar__left">
|
||||||
|
Custom Left
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`should render slots correctly when set clickable to false 2`] = `
|
||||||
|
<div class="van-nav-bar__right">
|
||||||
|
Custom Right
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`should render title slot correctly 1`] = `
|
exports[`should render title slot correctly 1`] = `
|
||||||
<div class="van-nav-bar__title van-ellipsis">
|
<div class="van-nav-bar__title van-ellipsis">
|
||||||
Custom Title
|
Custom Title
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { NavBar } from '..';
|
import { NavBar } from '..';
|
||||||
|
import { HAPTICS_FEEDBACK } from '../../utils';
|
||||||
import { mount, mockGetBoundingClientRect, later } from '../../../test';
|
import { mount, mockGetBoundingClientRect, later } from '../../../test';
|
||||||
|
|
||||||
test('should render left slot correctly', () => {
|
test('should render left slot correctly', () => {
|
||||||
@ -9,6 +10,9 @@ test('should render left slot correctly', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.find('.van-nav-bar__left').html()).toMatchSnapshot();
|
expect(wrapper.find('.van-nav-bar__left').html()).toMatchSnapshot();
|
||||||
|
expect(
|
||||||
|
wrapper.find('.van-nav-bar__left').classes(HAPTICS_FEEDBACK)
|
||||||
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render left slot correctly', () => {
|
test('should render left slot correctly', () => {
|
||||||
@ -19,6 +23,9 @@ test('should render left slot correctly', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.find('.van-nav-bar__right').html()).toMatchSnapshot();
|
expect(wrapper.find('.van-nav-bar__right').html()).toMatchSnapshot();
|
||||||
|
expect(
|
||||||
|
wrapper.find('.van-nav-bar__right').classes(HAPTICS_FEEDBACK)
|
||||||
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render title slot correctly', () => {
|
test('should render title slot correctly', () => {
|
||||||
@ -85,3 +92,22 @@ test('should change z-index when using z-index prop', () => {
|
|||||||
});
|
});
|
||||||
expect(wrapper.style.zIndex).toEqual('100');
|
expect(wrapper.style.zIndex).toEqual('100');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should render slots correctly when set clickable to false', () => {
|
||||||
|
const wrapper = mount(NavBar, {
|
||||||
|
slots: {
|
||||||
|
left: () => 'Custom Left',
|
||||||
|
right: () => 'Custom Right',
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
clickable: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const leftDom = wrapper.find('.van-nav-bar__left');
|
||||||
|
const rightDom = wrapper.find('.van-nav-bar__right');
|
||||||
|
expect(leftDom.html()).toMatchSnapshot();
|
||||||
|
expect(rightDom.html()).toMatchSnapshot();
|
||||||
|
expect(leftDom.classes(HAPTICS_FEEDBACK)).toBeFalsy();
|
||||||
|
expect(rightDom.classes(HAPTICS_FEEDBACK)).toBeFalsy();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user