-
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
base: v5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+74
to
+85
Contributor
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. The current implementation for combining options might lead to issues. To fix this, I recommend using a deep merge for the options, especially for the
Suggested change
Contributor
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. @XiaoMing-xmg666 这里得改下 Object.assign 可能会意外覆盖 style |
||||||||||||||||||||||||||||||||||||||||||||||||
| this.render(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.bindEvents(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -299,7 +311,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> { | |||||||||||||||||||||||||||||||||||||||||||||||
| x, | ||||||||||||||||||||||||||||||||||||||||||||||||
| y, | ||||||||||||||||||||||||||||||||||||||||||||||||
| style: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| '.tooltip': { | ||||||||||||||||||||||||||||||||||||||||||||||||
| [`.${this.options.prefixCls || ''}tooltip`]: { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. Similar to the constructor, the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| visibility: 'visible', | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -350,12 +362,14 @@ export class Tooltip extends BasePlugin<TooltipOptions> { | |||||||||||||||||||||||||||||||||||||||||||||||
| enterable, | ||||||||||||||||||||||||||||||||||||||||||||||||
| offset, | ||||||||||||||||||||||||||||||||||||||||||||||||
| style, | ||||||||||||||||||||||||||||||||||||||||||||||||
| template: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| prefixCls: this.options.prefixCls || '', | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+365
to
+367
Member
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); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||

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
prefixClsoption is used to construct a CSS selector key without any sanitization. This creates a potential CSS Injection and Cross-Site Scripting (XSS) vulnerability if an attacker can control this option, as they could inject malicious CSS rules. It is recommended to sanitize the input to allow only safe characters like alphanumeric characters, hyphens, and underscores.