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

Core Component and Tooltip event handling tweaks #330

Merged
merged 3 commits into from
Feb 6, 2024
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
2 changes: 1 addition & 1 deletion packages/ts/src/components/tooltip/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface TooltipConfigInterface {
* ```
*/
triggers?: {
[selector: string]: (data: any, i: number, elements: (HTMLElement | SVGElement)[]) => string | HTMLElement | undefined | null;
[selector: string]: ((data: any, i: number, elements: (HTMLElement | SVGElement)[]) => string | HTMLElement | undefined | null) | undefined | null;
};
/** Custom DOM attributes for the tooltip. Useful when you need to refer to a specific tooltip instance
* by using a CSS selector. Attributes configuration object has the following structure:
Expand Down
4 changes: 3 additions & 1 deletion packages/ts/src/components/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class Tooltip {
private _setContainerPosition (): void {
// Tooltip position calculation relies on the parent position
// If it's not set (static), we set it to `relative` (not a good practice)
if (getComputedStyle(this._container)?.position === 'static') {
if (this._container !== document.body && getComputedStyle(this._container)?.position === 'static') {
this._container.style.position = 'relative'
}
}
Expand All @@ -185,6 +185,8 @@ export class Tooltip {
// Go through all of the configured triggers
for (const className of Object.keys(triggers)) {
const template = triggers[className]
if (!template) continue // Skip if the trigger is not configured

const els = selection.selectAll<HTMLElement | SVGGElement, unknown>(`.${className}`).nodes()

// Go through all of the elements in the event path (from the deepest element upwards)
Expand Down
2 changes: 1 addition & 1 deletion packages/ts/src/core/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class ComponentCore<
const els = selection.nodes()
const i = els.indexOf(event.currentTarget as SVGGElement | HTMLElement)
const eventFunction = events[className][eventType as VisEventType]
return eventFunction(d, event, i, els)
return eventFunction?.(d, event, i, els)
})
})
})
Expand Down
Loading