-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: add plugin tooltip option prefixCls #7512
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
Open
XiaoMing-xmg666
wants to merge
1
commit into
v5
Choose a base branch
from
feat/xmg/tooltip-prefixcls
base: v5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+82
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,12 @@ export interface TooltipOptions | |
| * <en/> Callback executed when visibility of the tooltip card is changed | ||
| */ | ||
| onOpenChange: (open: boolean) => void; | ||
| /** | ||
| * <zh/> 自定义类名前缀 | ||
| * | ||
| * <en/> Custom class name prefix | ||
| */ | ||
| prefixCls?: string; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -59,18 +65,24 @@ export class Tooltip extends BasePlugin<TooltipOptions> { | |
| enterable: false, | ||
| enable: true, | ||
| offset: [10, 10], | ||
| style: { | ||
| '.tooltip': { | ||
| visibility: 'hidden', | ||
| }, | ||
| }, | ||
| }; | ||
| private currentTarget: string | null = null; | ||
| private tooltipElement: TooltipComponent | null = null; | ||
| private container: HTMLElement | null = null; | ||
|
|
||
| constructor(context: RuntimeContext, options: TooltipOptions) { | ||
| super(context, Object.assign({}, Tooltip.defaultOptions, options)); | ||
| const combineOptions = Object.assign( | ||
| { | ||
| style: { | ||
| [`.${options.prefixCls || ''}tooltip`]: { | ||
| visibility: 'hidden', | ||
| }, | ||
| }, | ||
| }, | ||
| Tooltip.defaultOptions, | ||
| options, | ||
| ); | ||
| super(context, combineOptions); | ||
| this.render(); | ||
| this.bindEvents(); | ||
| } | ||
|
|
@@ -299,7 +311,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> { | |
| x, | ||
| y, | ||
| style: { | ||
| '.tooltip': { | ||
| [`.${this.options.prefixCls || ''}tooltip`]: { | ||
| visibility: 'visible', | ||
| }, | ||
| }, | ||
|
|
@@ -350,12 +362,14 @@ export class Tooltip extends BasePlugin<TooltipOptions> { | |
| enterable, | ||
| offset, | ||
| style, | ||
| template: { | ||
| prefixCls: this.options.prefixCls || '', | ||
| }, | ||
|
Comment on lines
+365
to
+367
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }; | ||
| } | ||
|
|
||
| private initTooltip = () => { | ||
| const tooltipElement = new TooltipComponent({ | ||
| className: 'tooltip', | ||
| style: this.tooltipStyleProps, | ||
| }); | ||
| this.container?.appendChild(tooltipElement.HTMLTooltipElement); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation for combining options might lead to issues.
Object.assignperforms a shallow merge. If a user provides astyleobject in theoptions, it will completely overwrite the defaultstylethat setsvisibility: 'hidden'. This could cause the tooltip to be visible by default, which is likely not the intended behavior and a regression for users customizing styles.To fix this, I recommend using a deep merge for the options, especially for the
styleproperty. This ensures that user-provided styles are merged with the default styles, preserving the essentialvisibility: 'hidden'rule. You'll need to importdeepMixfrom@antv/utilat the top of the file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XiaoMing-xmg666 这里得改下 Object.assign 可能会意外覆盖 style