Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tag): 增加tooltipProps参数 (#2678) #2683

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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