Skip to content

Commit

Permalink
Merge pull request #2683 from XiaoMi/feature/2678(tag)
Browse files Browse the repository at this point in the history
feat(tag): 增加tooltipProps参数 (#2678)
  • Loading branch information
solarjoker authored Dec 1, 2023
2 parents b82e0bf + faa5d6e commit 0f0c985
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-moons-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(tag): 增加 tooltipProps 参数
5 changes: 5 additions & 0 deletions .changeset/slow-tables-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/tag": minor
---

feat: 增加 tooltipProps 参数
11 changes: 9 additions & 2 deletions packages/ui/tag/src/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef, useMemo, useState, useEffect, useRef } from 'react'
import { cx, getPrefixCls } from '@hi-ui/classname'
import { CloseOutlined } from '@hi-ui/icons'
import { __DEV__, invariant } from '@hi-ui/env'
import { Tooltip } from '@hi-ui/tooltip'
import { Tooltip, TooltipProps } from '@hi-ui/tooltip'
import { HiBaseHTMLProps } from '@hi-ui/core'

const _role = 'tag'
Expand Down Expand Up @@ -36,6 +36,7 @@ export const Tag = forwardRef<HTMLDivElement | null, TagProps>(
autoEditable = false,
maxWidth,
render = DEFAULT_RENDER,
tooltipProps,
...rest
},
ref
Expand Down Expand Up @@ -116,6 +117,7 @@ export const Tag = forwardRef<HTMLDivElement | null, TagProps>(
? {
component: Tooltip,
componentProps: {
...tooltipProps,
title: render(children as React.ReactText),
trigger: 'hover',
},
Expand All @@ -124,7 +126,7 @@ export const Tag = forwardRef<HTMLDivElement | null, TagProps>(
component: React.Fragment,
componentProps: {},
},
[isShowPopover, children, isInEdit, render]
[isShowPopover, isInEdit, tooltipProps, render, children]
)

if (__DEV__) {
Expand Down Expand Up @@ -244,6 +246,11 @@ export interface TagProps extends HiBaseHTMLProps<'div'> {
* @default 0 代表不限制宽度
*/
maxWidth?: number
/**
* Tooltip 组件参数设置
* @private
*/
tooltipProps?: Omit<TooltipProps, 'title'>
}

if (__DEV__) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/tag/stories/max-width.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const MaxWidth = () => {
<h1>Tag MaxWidth</h1>
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
<Tag maxWidth={240}>max 240px (placeholder1 placeholder2 placeholder3 placeholder4)</Tag>
<Tag maxWidth={240} closeable>
{/* Tooltip 禁用 portal */}
<Tag maxWidth={240} closeable tooltipProps={{ disabledPortal: true }}>
max 240px (placeholder1 placeholder2 placeholder3 placeholder4)
</Tag>
<Tag maxWidth={180} editable onEdit={setMaxEditableValue}>
Expand Down

0 comments on commit 0f0c985

Please sign in to comment.