Skip to content

Commit 0947ba7

Browse files
RSS1102tdesign-bot
andauthored
feat(popup): expose popper instance through getPopper method (#6096)
* feat(popup): expose `popper` instance through `getPopper` method * feat(popup): 添加 `getPopper` 方法以获取当前组件的 popper 实例,并更新相关文档 * docs(popup): 修正 `getPopper` 方法的类型描述,去除多余空格 * fix(popup): 更新 `getPopper` 方法的返回类型为 `Instance` * fix(popup): 更新 `getOverlay` 和 `getPopper` 方法的返回类型为 `HTMLElement | null` 和 `Instance | null` * chore: stash changelog [ci skip] * chore: stash changelog [ci skip] --------- Co-authored-by: tdesign-bot <[email protected]>
1 parent 5ec3cfa commit 0947ba7

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

packages/components/popup/popup.en-US.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
:: BASE_DOC ::
22

33
## API
4+
45
### Popup Props
56

67
name | type | default | description | required
@@ -42,6 +43,7 @@ visible-change | `(visible: boolean, context: PopupVisibleChangeContext)` | [see
4243

4344
name | params | return | description
4445
-- | -- | -- | --
45-
getOverlay | \- | `HTMLElement` | used to get overly html element
46+
getOverlay | \- | `HTMLElement \| null` | used to get overly html element
4647
getOverlayState | \- | `{ hover: boolean }` | get mouseover state of overlay
48+
getPopper | \- | `Instance \| null` | get the popup component popper instance。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/popup/type.ts)。<br/>`import { Instance } from '@popperjs/core'`<br/>
4749
update | \- | \- | used to update overlay content

packages/components/popup/popup.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737
如果您不确定问题是否是由该规则引起的,或者确定该规则不是问题的根本原因,请在 `GitHub` 上提出一个 `issue`,并提供可以重现问题的代码。这将有助于我们更好地了解您的问题并提供更好的帮助。
3838

3939
## API
40+
4041
### Popup Props
4142

42-
名称 | 类型 | 默认值 | 说明 | 必传
43+
名称 | 类型 | 默认值 | 描述 | 必传
4344
-- | -- | -- | -- | --
44-
attach | String / Function | 'body' | 制定挂载节点。数据类型为 String 时,会被当作选择器处理,进行节点查询。示例:'body' 或 () => document.body。TS 类型:`AttachNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
45+
attach | String / Function | 'body' | 指定挂载节点。数据类型为 String 时,会被当作选择器处理,进行节点查询。示例:'body' 或 () => document.body。TS 类型:`AttachNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
4546
content | String / Slot / Function | - | 浮层里面的内容。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
4647
default | String / Slot / Function | - | 触发元素,同 triggerElement。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
4748
delay | Number / Array | - | 延时显示或隐藏浮层,[延迟显示的时间,延迟隐藏的时间],单位:毫秒。如果只有一个时间,则表示显示和隐藏的延迟时间相同。示例 `'300'` 或者 `[200, 200]`。默认为:[250, 150]。TS 类型:`number \| Array<number>` | N
@@ -78,6 +79,7 @@ visible-change | `(visible: boolean, context: PopupVisibleChangeContext)` | 当
7879

7980
名称 | 参数 | 返回值 | 描述
8081
-- | -- | -- | --
81-
getOverlay | \- | `HTMLElement` | 获取浮层元素
82+
getOverlay | \- | `HTMLElement \| null` | 获取浮层元素
8283
getOverlayState | \- | `{ hover: boolean }` | 获取浮层悬浮状态
84+
getPopper | \- | `Instance \| null` | 获取当前组件 popper 实例。[详细类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/popup/type.ts)。<br/>`import { Instance } from '@popperjs/core'`<br/>
8385
update | \- | \- | 更新浮层内容

packages/components/popup/popup.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export default defineComponent({
249249
getOverlayState: () => ({
250250
hover: isOverlayHover.value,
251251
}),
252+
getPopper: () => popper,
252253
/** close is going to be deprecated. visible is enough */
253254
close: () => hide(),
254255
});

packages/components/popup/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { TdPopupProps } from './type';
88
import { PropType } from 'vue';
99

1010
export default {
11-
/** 制定挂载节点。数据类型为 String 时,会被当作选择器处理,进行节点查询。示例:'body' 或 () => document.body */
11+
/** 指定挂载节点。数据类型为 String 时,会被当作选择器处理,进行节点查询。示例:'body' 或 () => document.body */
1212
attach: {
1313
type: [String, Function] as PropType<TdPopupProps['attach']>,
1414
default: 'body' as TdPopupProps['attach'],

packages/components/popup/type.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
55
* */
66

7+
import { Instance } from '@popperjs/core';
78
import { TNode, ClassName, Styles, AttachNode } from '../common';
89

910
export interface TdPopupProps {
1011
/**
11-
* 制定挂载节点。数据类型为 String 时,会被当作选择器处理,进行节点查询。示例:'body' 或 () => document.body
12+
* 指定挂载节点。数据类型为 String 时,会被当作选择器处理,进行节点查询。示例:'body' 或 () => document.body
1213
* @default 'body'
1314
*/
1415
attach?: AttachNode;
@@ -116,11 +117,15 @@ export interface PopupInstanceFunctions {
116117
/**
117118
* 获取浮层元素
118119
*/
119-
getOverlay?: () => HTMLElement;
120+
getOverlay?: () => HTMLElement | null;
120121
/**
121122
* 获取浮层悬浮状态
122123
*/
123124
getOverlayState?: () => { hover: boolean };
125+
/**
126+
* 获取当前组件 popper 实例
127+
*/
128+
getPopper?: () => Instance | null;
124129
/**
125130
* 更新浮层内容
126131
*/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 6096
3+
contributor: RSS1102
4+
---
5+
6+
- feat(popup): 新增 `getPopper()` 方法,将返回 popper 实例,用于基于 popper 进行动态操作的场景 @RSS1102 ([#6096](https://github.com/Tencent/tdesign-vue-next/pull/6096))

0 commit comments

Comments
 (0)