Skip to content

Tooltip should hide when dialog is closed. #2030

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

Merged
merged 8 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Tooltip should hide when dialog is closed.
  • Loading branch information
rvanderveen058 committed May 9, 2025
commit 8e5079f1b75e3c1490a0fe01df66e754aaa5783b
30 changes: 30 additions & 0 deletions packages/components/tooltip/src/tooltip.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@sl-design-system/button/register.js';
import '@sl-design-system/button-bar/register.js';
import '@sl-design-system/dialog/register.js';
import '@sl-design-system/spinner/register.js';
import { type Meta, type StoryObj } from '@storybook/web-components';
import { type TemplateResult, html } from 'lit';
Expand Down Expand Up @@ -134,3 +135,32 @@ export const All: Story = {
`;
}
};

export const Dialog: Story = {
render: () => {
const onClick = async (event: Event & { target: HTMLElement }) => {
const dialog = document.createElement('sl-dialog');
dialog.innerHTML = `
<span slot="title">Tooltip</span>
Tooltip should be closed when the dialog is closed..
<sl-button slot="primary-actions" sl-dialog-close variant="primary">Close</sl-button>
`;
dialog.addEventListener('sl-close', () => dialog.remove());
event.target.insertAdjacentElement('afterend', dialog);
await dialog.updateComplete;
dialog.showModal();
};

return html`
<style>
#root-inner {
display: grid;
height: calc(20rem);
place-items: center;
}
</style>
<sl-button aria-describedby="tooltip" @click=${onClick}> Button </sl-button>
<sl-tooltip id="tooltip" position="top" max-width="300">This is the tooltip message</sl-tooltip>
`;
}
};
8 changes: 7 additions & 1 deletion packages/components/tooltip/src/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,18 @@ export class Tooltip extends LitElement {
#onHide = (event: Event): void => {
let toTooltip = false;
let fromTooltip = false;
let fromDialog = false;

if (event instanceof PointerEvent) {
toTooltip = (event.relatedTarget as Element)?.nodeName === 'SL-TOOLTIP';

fromDialog =
(event.target as Element)?.nodeName === 'SL-DIALOG' || (event.target as Element)?.nodeName === 'SL-BUTTON';
fromTooltip =
(event.target as Element)?.nodeName === 'SL-TOOLTIP' && !this.#matchesAnchor(event.relatedTarget as Element);
}
if ((this.#matchesAnchor(event.target as Element) && !toTooltip) || fromTooltip) {

if ((this.#matchesAnchor(event.target as Element) && !toTooltip) || fromTooltip || fromDialog) {
this.hidePopover();
}
};
Expand Down