Skip to content
Open
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
55 changes: 29 additions & 26 deletions src/app/shared/lang-switch/lang-switch.component.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
@if (moreThanOneLanguage) {
<div ngbDropdown class="navbar-nav" display="dynamic" placement="bottom-right">
<button role="button"
[attr.aria-label]="'nav.language' |translate"
aria-controls="language-menu-list"
aria-haspopup="menu"
class="dropdown-toggle btn btn-link px-0"
[title]="'nav.language' | translate"
(click)="$event.preventDefault()" data-bs-toggle="dropdown" ngbDropdownToggle
data-test="lang-switch"
tabindex="0">
<i class="fas fa-globe-asia fa-lg fa-fw"></i>
</button>
<div ngbDropdownMenu class="dropdown-menu" [attr.aria-label]="'nav.language' |translate" id="language-menu-list"
role="listbox">
@for (lang of translate.getLangs(); track lang) {
<div class="dropdown-item" tabindex="0"
role="option"
[lang]="lang"
(keyup.enter)="useLang(lang)"
(click)="useLang(lang)"
[attr.aria-selected]="lang === translate.getCurrentLang()"
[class.active]="lang === translate.getCurrentLang()">
{{ langLabel(lang) }}
</div>
}
<!-- Not rendered during SSR: the switch is only useful to interactive human users -->
@defer {
<div ngbDropdown class="navbar-nav" display="dynamic" placement="bottom-right">
<button role="button"
[attr.aria-label]="'nav.language' |translate"
aria-controls="language-menu-list"
aria-haspopup="menu"
class="dropdown-toggle btn btn-link px-0"
[title]="'nav.language' | translate"
(click)="$event.preventDefault()" data-bs-toggle="dropdown" ngbDropdownToggle
data-test="lang-switch"
tabindex="0">
<i class="fas fa-globe-asia fa-lg fa-fw"></i>
</button>
<div ngbDropdownMenu class="dropdown-menu" [attr.aria-label]="'nav.language' |translate" id="language-menu-list"
role="listbox">
@for (lang of translate.getLangs(); track lang) {
<div class="dropdown-item" tabindex="0"
role="option"
[lang]="lang"
(keyup.enter)="useLang(lang)"
(click)="useLang(lang)"
[attr.aria-selected]="lang === translate.getCurrentLang()"
[class.active]="lang === translate.getCurrentLang()">
{{ langLabel(lang) }}
</div>
}
</div>
</div>
</div>
}
}
6 changes: 5 additions & 1 deletion src/app/shared/lang-switch/lang-switch.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@angular/core';
import {
ComponentFixture,
DeferBlockState,
TestBed,
waitForAsync,
} from '@angular/core/testing';
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('LangSwitchComponent', () => {
provideHttpClientTesting(),
],
}).compileComponents()
.then(() => {
.then(async () => {
translate = TestBed.inject(TranslateService);
translate.addLangs(mockConfig.languages.filter((langConfig: LangConfig) => langConfig.active === true).map((a) => a.code));
translate.setFallbackLang('en');
Expand All @@ -103,6 +104,9 @@ describe('LangSwitchComponent', () => {
de = fixture.debugElement;
langSwitchElement = de.nativeElement;
fixture.detectChanges();
// The language dropdown is wrapped in a @defer block (not rendered during SSR), so we need to render it explicitly
const deferBlock = await fixture.getDeferBlocks();
await deferBlock[0].render(DeferBlockState.Complete);
});
}));

Expand Down
Loading