Skip to content
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
26 changes: 26 additions & 0 deletions playwright/e2e/element-examples/navbar-vertical.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ test.describe('navbar vertical', () => {
await si.runVisualAndA11yTests('collapsed-flyout');
});

test('it should show tooltip only on keyboard interaction', async ({ page, si }) => {
await si.visitExample(example);
await page.getByLabel('collapse', { exact: true }).click();
await expect(page.getByLabel('expand', { exact: true })).toBeVisible();
await si.waitForAllAnimationsToComplete();
const userManagement = page.getByRole('button', { name: 'User management' });
const tooltip = page.getByRole('tooltip', { name: 'User management' });
const group = page.getByRole('group', { name: 'User management' });

// This checks the tooltip is visible when using the keyboard
await userManagement.focus();
await userManagement.press('Enter');
await expect(group.getByRole('link', { name: 'Sub item', exact: true })).toBeFocused();
await group.press('Escape');
await expect(tooltip).toBeVisible();
await expect(userManagement).toBeFocused();

// This check the tooltip is not visible whe using the mouse
await userManagement.click();
await group.hover();
await expect(tooltip).not.toBeVisible();
await page.getByRole('main').click(); // outside click to hide flyout
await expect(userManagement).toBeFocused();
await expect(tooltip).not.toBeVisible();
});

test(example + ' mobile collapsed', async ({ page, si }) => {
await page.setViewportSize({ width: 570, height: 600 });
await si.visitExample(example, false);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions projects/element-ng/tooltip/si-tooltip.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('SiTooltipDirective', () => {
fixture = TestBed.createComponent(TestHostComponent);
component = fixture.componentInstance;
button = fixture.nativeElement.querySelector('button') as HTMLButtonElement;
spyOn(button, 'matches').and.returnValue(true);
fixture.detectChanges();
});

Expand Down Expand Up @@ -112,6 +113,7 @@ describe('SiTooltipDirective', () => {
jasmine.clock().install();
fixture = TestBed.createComponent(TestHostComponent);
button = fixture.nativeElement.querySelector('button') as HTMLButtonElement;
spyOn(button, 'matches').and.returnValue(true);
fixture.detectChanges();
});

Expand Down
11 changes: 8 additions & 3 deletions projects/element-ng/tooltip/si-tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
* Copyright (c) Siemens 2016 - 2026
* SPDX-License-Identifier: MIT
*/
import { isPlatformBrowser } from '@angular/common';
import {
booleanAttribute,
Directive,
ElementRef,
inject,
input,
OnDestroy,
PLATFORM_ID,
TemplateRef
} from '@angular/core';
import { positions } from '@siemens/element-ng/common';
Expand All @@ -21,7 +23,7 @@ import { SiTooltipService, TooltipRef } from './si-tooltip.service';
providers: [SiTooltipService],
host: {
'[attr.aria-describedby]': 'describedBy',
'(focus)': 'focusIn()',
'(focus)': 'focusIn($event)',
'(mouseenter)': 'show()',
'(touchstart)': 'hide()',
'(focusout)': 'hide()',
Expand Down Expand Up @@ -63,6 +65,7 @@ export class SiTooltipDirective implements OnDestroy {
private showTimeout?: ReturnType<typeof setTimeout>;
private tooltipService = inject(SiTooltipService);
private elementRef = inject(ElementRef);
private isBrowser = isPlatformBrowser(inject(PLATFORM_ID));

ngOnDestroy(): void {
this.clearShowTimeout();
Expand Down Expand Up @@ -98,8 +101,10 @@ export class SiTooltipDirective implements OnDestroy {
}, delay);
}

protected focusIn(): void {
this.showTooltip(true);
protected focusIn(event: FocusEvent): void {
if (this.isBrowser && (event.target as Element).matches(':focus-visible')) {
this.showTooltip(true);
}
}

protected show(): void {
Expand Down
Loading