From d9726883e6617189e60d155ec6edabd88aea8e04 Mon Sep 17 00:00:00 2001 From: inottn Date: Sun, 28 May 2023 16:01:15 +0800 Subject: [PATCH] feat(Popover): add actions-direction prop (#11888) * feat(Popover): add direction prop * fix: solve some problems --- packages/vant/src/popover/Popover.tsx | 20 ++++++-- packages/vant/src/popover/README.md | 46 +++++++++++++++++-- packages/vant/src/popover/README.zh-CN.md | 40 ++++++++++++++++ packages/vant/src/popover/demo/index.vue | 36 +++++++++++++++ packages/vant/src/popover/index.less | 23 ++++++++++ .../test/__snapshots__/demo-ssr.spec.ts.snap | 33 +++++++++++++ .../test/__snapshots__/demo.spec.ts.snap | 24 ++++++++++ .../test/__snapshots__/index.spec.tsx.snap | 8 ++-- packages/vant/src/popover/test/index.spec.tsx | 15 ++++++ packages/vant/src/popover/types.ts | 1 + packages/vant/src/utils/constant.ts | 1 + 11 files changed, 237 insertions(+), 10 deletions(-) diff --git a/packages/vant/src/popover/Popover.tsx b/packages/vant/src/popover/Popover.tsx index 39682aab8..d2a4f4397 100644 --- a/packages/vant/src/popover/Popover.tsx +++ b/packages/vant/src/popover/Popover.tsx @@ -21,6 +21,7 @@ import { truthProp, numericProp, unknownProp, + BORDER_RIGHT, BORDER_BOTTOM, makeArrayProp, makeStringProp, @@ -40,6 +41,7 @@ import { Popup } from '../popup'; import { PopoverTheme, PopoverAction, + PopoverActionsDirection, PopoverTrigger, PopoverPlacement, } from './types'; @@ -60,6 +62,7 @@ export const popoverProps = { theme: makeStringProp('light'), overlay: Boolean, actions: makeArrayProp(), + actionsDirection: makeStringProp('vertical'), trigger: makeStringProp('click'), duration: numericProp, showArrow: truthProp, @@ -193,7 +196,14 @@ export default defineComponent({ class={bem('action-icon')} /> ), -
{action.text}
, +
+ {action.text} +
, ]; }; @@ -202,7 +212,11 @@ export default defineComponent({ return ( +
+ + + + + + +
@@ -89,7 +89,7 @@ exports[`should locate to reference element when showed 3`] = `
@@ -120,7 +120,7 @@ exports[`should watch placement prop and update location 1`] = `
diff --git a/packages/vant/src/popover/test/index.spec.tsx b/packages/vant/src/popover/test/index.spec.tsx index fbfd3bc42..4ad3bcada 100644 --- a/packages/vant/src/popover/test/index.spec.tsx +++ b/packages/vant/src/popover/test/index.spec.tsx @@ -227,3 +227,18 @@ test('should render action slot correctly', () => { expect(wrapper.find('.van-popover__action').html()).toMatchSnapshot(); }); + +test('should add "van-popover__content--horizontal" class when actions-direction prop is horizontal', () => { + const wrapper = mount(Popover, { + props: { + show: true, + actions: baseActions, + actionsDirection: 'horizontal', + teleport: null, + }, + }); + + expect(wrapper.find('.van-popover__content').classes()).toContain( + 'van-popover__content--horizontal' + ); +}); diff --git a/packages/vant/src/popover/types.ts b/packages/vant/src/popover/types.ts index 6001e8042..d91c08672 100644 --- a/packages/vant/src/popover/types.ts +++ b/packages/vant/src/popover/types.ts @@ -1,4 +1,5 @@ export type PopoverTheme = 'light' | 'dark'; +export type PopoverActionsDirection = 'horizontal' | 'vertical'; export type PopoverTrigger = 'manual' | 'click'; export type PopoverPlacement = | 'top' diff --git a/packages/vant/src/utils/constant.ts b/packages/vant/src/utils/constant.ts index 08f92883a..f111723e3 100644 --- a/packages/vant/src/utils/constant.ts +++ b/packages/vant/src/utils/constant.ts @@ -4,6 +4,7 @@ import type { FormProvide } from '../form/types'; export const BORDER = 'van-hairline'; export const BORDER_TOP = `${BORDER}--top`; export const BORDER_LEFT = `${BORDER}--left`; +export const BORDER_RIGHT = `${BORDER}--right`; export const BORDER_BOTTOM = `${BORDER}--bottom`; export const BORDER_SURROUND = `${BORDER}--surround`; export const BORDER_TOP_BOTTOM = `${BORDER}--top-bottom`;