Refine shared header language selector

This commit is contained in:
2026-09-15 12:34:26 +02:00
parent 50bf79965f
commit 52a48cacb9
8 changed files with 135 additions and 42 deletions
+73 -25
View File
@@ -1,32 +1,80 @@
/* Persistent language choice, also available before login. */ /* Shared language/account controls, including pages shown before login. */
.language-switch { .header-controls {
position: relative;
z-index: 2000;
display: flex;
flex-wrap: nowrap;
align-items: center;
justify-content: flex-end;
gap: 6px;
min-width: 0;
max-width: 100%;
margin-left: auto;
}
.language-switch { position: relative; flex: 0 0 auto; margin: 0; padding: 0; }
.language-switch > summary {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
flex: 0 0 auto; gap: 5px;
margin: 0; min-height: 44px;
padding: 0; padding: 6px 8px;
border: 1px solid transparent;
border-radius: 9px;
color: var(--muted, #57534e);
background: transparent;
font: 500 .85rem/1.2 system-ui, sans-serif;
white-space: nowrap;
cursor: pointer;
list-style: none;
} }
.language-switch a { .language-switch > summary::-webkit-details-marker { display: none; }
display: inline-flex; .language-caret { font-size: .7rem; }
align-items: center; .language-switch[open] > summary,
justify-content: center; .language-switch > summary:active { color: var(--text, #f5f5f4); background: var(--surface-hover, #1a1111); border-color: var(--border, #3a3030); }
width: 38px; .language-panel {
height: 36px; position: absolute;
border: 1px solid var(--border, #30363d); top: calc(100% + 6px);
border-radius: 8px; right: 0;
color: var(--text, #222); z-index: 10000;
font-family: system-ui, sans-serif; width: 200px;
font-size: 1.2rem; max-width: calc(100vw - 24px);
line-height: 1; padding: 6px;
text-decoration: none; border: 1px solid var(--border, #3a3030);
border-radius: 10px;
color: var(--text, #f5f5f4);
background: var(--surface, #101010);
box-shadow: 0 14px 35px rgba(0,0,0,.65);
} }
.language-switch a.active { background: #922525; color: #fff; border-color: #c74747; } .language-heading { margin: 0; padding: 8px 10px; font-size: .8rem; color: var(--muted, #a8a29e); }
.language-switch a:focus-visible { outline: 2px solid #fff; outline-offset: 3px; } .language-panel a { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 10px; border-radius: 6px; color: inherit; font: 400 .9rem/1.3 system-ui, sans-serif; text-decoration: none; }
.language-switch a:hover { background: #7f1d1d; } .language-panel a[aria-current] { background: var(--surface-hover, #1a1111); font-weight: 700; }
.header-controls { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-left: auto; } .language-selected { margin-left: auto; }
.header-controls .user-menu { margin-left: 0; } .language-switch summary:focus-visible { outline: 2px solid var(--text, #57534e); outline-offset: 2px; }
.language-panel a:focus-visible,
.header-controls .user-menu summary:focus-visible { outline: 2px solid var(--text, #f5f5f4); outline-offset: 2px; }
@media (hover: hover) {
.language-switch > summary:hover { color: var(--text, #f5f5f4); background: var(--surface-hover, #1a1111); border-color: var(--border, #3a3030); }
.language-panel a:hover { background: var(--surface-hover, #1a1111); }
}
/* Both menus anchor to the same right edge, independent of the page header. */
.header-controls .language-switch,
.header-controls .user-menu { position: static; margin-left: 0; }
.header-controls .user-menu { min-width: 0; }
.header-controls .user-menu summary { display: flex; align-items: center; gap: 5px; min-height: 44px; max-width: 220px; }
.user-menu-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-controls .metal-notification { flex-shrink: 0; margin-right: 7px; }
.header-controls .user-menu-panel { position: absolute; top: calc(100% + 6px); right: 0; max-width: calc(100vw - 24px); max-height: calc(100dvh - 90px); overflow-y: auto; }
.header-inner { gap: 8px; }
.header-inner > .logo { min-width: 0; flex-shrink: 1; }
.header-inner > .logo .brand-logo { max-width: 100% !important; }
.header-inner > .language-switch { margin-left: auto; } .header-inner > .language-switch { margin-left: auto; }
.header-actions > .header-controls { flex: 0 0 auto; } .detail-topbar { align-items: center; padding-inline: 12px; }
.detail-topbar > .header-controls { flex: 0 0 auto; } .detail-topbar > .back-link { min-width: 0; overflow-wrap: anywhere; }
.detail-topbar > .header-controls { flex-shrink: 0; }
.registration-header { display: flex; justify-content: flex-end; margin: -36px 0 12px; } .registration-header { display: flex; justify-content: flex-end; margin: -36px 0 12px; }
@media (max-width: 600px) {
.header-controls .user-menu summary { max-width: 30vw; padding: 8px; }
.language-switch > summary { padding: 6px; }
.detail-topbar { gap: 8px; }
}
-2
View File
@@ -232,7 +232,6 @@ main {
.logo { max-width: 130px; } .logo { max-width: 130px; }
.brand-logo { width: 130px !important; max-width: 130px !important; height: 40px !important; max-height: 40px !important; } .brand-logo { width: 130px !important; max-width: 130px !important; height: 40px !important; max-height: 40px !important; }
.header-controls .user-menu summary { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { main {
padding: 22px 15px 80px; padding: 22px 15px 80px;
@@ -248,7 +247,6 @@ main {
.header-actions { width: 100%; justify-content: flex-start; } .header-actions { width: 100%; justify-content: flex-start; }
.header-actions > a { flex: 1 1 auto; text-align: center; } .header-actions > a { flex: 1 1 auto; text-align: center; }
.header-actions > .header-controls { margin-left: auto; }
} }
form { form {
max-width: 650px; max-width: 650px;
+24
View File
@@ -0,0 +1,24 @@
/* Native details/summary provides keyboard activation and expanded state. */
(() => {
const selector = '.language-switch, .header-controls .user-menu';
document.addEventListener('toggle', event => {
if (!event.target.matches(selector) || !event.target.open) return;
document.querySelectorAll(selector).forEach(menu => {
if (menu !== event.target) menu.open = false;
});
}, true);
document.addEventListener('click', event => {
document.querySelectorAll(selector).forEach(menu => {
if (menu.open && !menu.contains(event.target)) menu.open = false;
});
});
document.addEventListener('keydown', event => {
if (event.key !== 'Escape') return;
document.querySelectorAll(selector).forEach(menu => {
if (!menu.open) return;
menu.open = false;
menu.querySelector('summary').focus();
event.preventDefault();
});
});
})();
+14 -4
View File
@@ -1,4 +1,14 @@
<nav class="language-switch" aria-label="{{ _('Sprache') }}"> <details class="language-switch">
{% set target_language = 'en' if language() == 'de' else 'de' %} <summary aria-label="{{ _('Sprache wechseln') }}: {{ language() | upper }}">
<a class="active" href="{{ language_url(target_language) }}" lang="{{ target_language }}" hreflang="{{ target_language }}" aria-label="{{ _('Zu Englisch wechseln') if target_language == 'en' else _('Zu Deutsch wechseln') }}" title="{{ _('Zu Englisch wechseln') if target_language == 'en' else _('Zu Deutsch wechseln') }}">{{ '🇬🇧' if target_language == 'en' else '🇩🇪' }}</a> <span aria-hidden="true">🌐</span> <span>{{ language() | upper }}</span> <span class="language-caret" aria-hidden="true"></span>
</nav> </summary>
<nav class="language-panel" aria-label="{{ _('Sprache') }}">
<p class="language-heading"><span aria-hidden="true">🌐</span> {{ _('Sprache') }}</p>
{% for code, flag, label in [('de', '🇩🇪', 'Deutsch'), ('en', '🇬🇧', 'English')] %}
<a href="{{ language_url(code) }}" lang="{{ code }}" hreflang="{{ code }}"{% if language() == code %} aria-current="true"{% endif %}>
<span aria-hidden="true">{{ flag }}</span> <span>{{ label }}</span>{% if language() == code %}<span class="language-selected" aria-hidden="true"></span>{% endif %}
</a>
{% endfor %}
</nav>
</details>
<script src="/static/js/header-controls.js" defer></script>
+1 -1
View File
@@ -1,5 +1,5 @@
<details class="user-menu"> <details class="user-menu">
<summary>{{ user.display_name }}{% if user.notification_count %} <span class="metal-notification" title="{{ user.notification_count }} {{ _('neue Nachricht(en) oder Anfrage(n)') }}" aria-label="{{ _('Neue Benachrichtigungen') }}">🤘<b>{{ user.notification_count }}</b></span>{% endif %}</summary> <summary><span aria-hidden="true"></span> <span class="user-menu-name">{{ user.display_name }}</span>{% if user.notification_count %} <span class="metal-notification" title="{{ user.notification_count }} {{ _('neue Nachricht(en) oder Anfrage(n)') }}" aria-label="{{ _('Neue Benachrichtigungen') }}">🤘<b>{{ user.notification_count }}</b></span>{% endif %}</summary>
<div class="user-menu-panel"> <div class="user-menu-panel">
<a href="/profile">{{ _('Mein Profil') }}</a> <a href="/profile">{{ _('Mein Profil') }}</a>
<a href="/messages">{{ _('Nachrichten') }}{% if user.notification_count %} <span class="metal-notification" title="{{ _('Neue Nachrichten oder Anfragen') }}" aria-label="{{ _('Neue Nachrichten oder Anfragen') }}">🤘<b>{{ user.notification_count }}</b></span>{% endif %}</a> <a href="/messages">{{ _('Nachrichten') }}{% if user.notification_count %} <span class="metal-notification" title="{{ _('Neue Nachrichten oder Anfragen') }}" aria-label="{{ _('Neue Nachrichten oder Anfragen') }}">🤘<b>{{ user.notification_count }}</b></span>{% endif %}</a>
+1 -1
View File
@@ -19,7 +19,7 @@
> >
<style> <style>
.detail-topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; } .detail-topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.event-type-badge { display: inline-block; margin-bottom: 8px; padding: 4px 9px; border: 1px solid #4b5563; border-radius: 999px; color: #c4b5fd; font-size: .8rem; font-weight: 700; text-transform: uppercase; } .event-type-badge { display: inline-block; margin-bottom: 8px; padding: 4px 9px; border: 1px solid #4b5563; border-radius: 999px; color: #c4b5fd; font-size: .8rem; font-weight: 700; text-transform: uppercase; }
.parent-event-link { color: #c4b5fd; } .parent-event-link { color: #c4b5fd; }
.flyer-source { display: block; width: 100%; flex: 0 0 100%; margin: 10px 0 0; color: #a8a29e; font-size: .85rem; text-align: center; } .flyer-source { display: block; width: 100%; flex: 0 0 100%; margin: 10px 0 0; color: #a8a29e; font-size: .85rem; text-align: center; }
+19 -8
View File
@@ -21,10 +21,10 @@
<style> <style>
.page-header { .page-header {
display: flex; display: grid;
justify-content: space-between; grid-template-columns: minmax(0, 1fr) auto;
align-items: center; align-items: center;
gap: 20px; gap: 12px 16px;
margin-bottom: 35px; margin-bottom: 35px;
} }
@@ -54,6 +54,7 @@
} }
.header-actions { .header-actions {
grid-column: 1 / -1;
display: flex; display: flex;
gap: 10px; gap: 10px;
align-items: center; align-items: center;
@@ -175,7 +176,7 @@
min-height: 100vh; min-height: 100vh;
} }
.page-header { padding: 24px; border: 1px solid #5f1515; border-left: 4px solid #dc2626; border-radius: 14px; background: linear-gradient(110deg, rgba(10,10,10,.9), rgba(69,10,10,.28)); box-shadow: 0 12px 30px rgba(0,0,0,.3); } .page-header { padding: 16px 20px; border: 1px solid #5f1515; border-left: 4px solid #dc2626; border-radius: 14px; background: linear-gradient(110deg, rgba(10,10,10,.9), rgba(69,10,10,.28)); box-shadow: 0 12px 30px rgba(0,0,0,.3); }
.page-header h1 { font-family: "Nimbus Sans Narrow", Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; letter-spacing: .05em; text-transform: uppercase; text-shadow: 0 2px 18px rgba(185, 28, 28, .45); } .page-header h1 { font-family: "Nimbus Sans Narrow", Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; letter-spacing: .05em; text-transform: uppercase; text-shadow: 0 2px 18px rgba(185, 28, 28, .45); }
.new-concert-button { background: #991b1b; border: 1px solid #dc2626; } .new-concert-button { background: #991b1b; border: 1px solid #dc2626; }
.new-concert-button:hover { background: #b91c1c; } .new-concert-button:hover { background: #b91c1c; }
@@ -185,13 +186,23 @@
.concert-date { color: #ef4444; } .concert-date { color: #ef4444; }
.concert-card.linked-event { border-left-color: #dc2626; background: #0d0d0d; } .concert-card.linked-event { border-left-color: #dc2626; background: #0d0d0d; }
@media (min-width: 1024px) {
.page-header { grid-template-columns: minmax(0, 1fr) auto auto; }
.page-header > .header-controls { grid-column: 3; grid-row: 1; }
.page-header > .header-actions { grid-column: 2; grid-row: 1; }
}
@media (max-width: 600px) { @media (max-width: 600px) {
.page-header { .page-header {
align-items: flex-start; padding: 12px;
flex-direction: column; gap: 10px;
} }
.page-header .subtitle { display: none; }
.page-header h1 { font-size: 1.25rem; overflow-wrap: anywhere; }
.page-header .brand-logo { max-width: 100% !important; }
.new-concert-button { .new-concert-button {
width: 100%; width: 100%;
text-align: center; text-align: center;
@@ -244,6 +255,8 @@
</div> </div>
{% include '_header_controls.html' %}
<div class="header-actions"> <div class="header-actions">
<a href="{% if archive %}/{% else %}/events/past{% endif %}" class="admin-button"> <a href="{% if archive %}/{% else %}/events/past{% endif %}" class="admin-button">
@@ -257,8 +270,6 @@
{{ _('+ Veranstaltung hinzufügen') }} {{ _('+ Veranstaltung hinzufügen') }}
</a> </a>
{% include '_header_controls.html' %}
</div> </div>
</header> </header>
+3 -1
View File
@@ -69,7 +69,9 @@ class TranslationTests(unittest.TestCase):
for path, title in [('/datenschutz', 'Privacy policy'), ('/impressum', 'Legal notice')]: for path, title in [('/datenschutz', 'Privacy policy'), ('/impressum', 'Legal notice')]:
page = client.get(path) page = client.get(path)
self.assertIn(title, page.text) self.assertIn(title, page.text)
self.assertIn('aria-label="Switch to German"', page.text) self.assertIn('aria-label="Switch language: EN"', page.text)
self.assertIn('lang="en" hreflang="en" aria-current="true"', page.text)
self.assertIn('>Deutsch</span>', page.text)
response = client.get('/language/de?next=/login') response = client.get('/language/de?next=/login')
self.assertIn('Anmelden', response.text) self.assertIn('Anmelden', response.text)
self.assertIn('<html lang="de">', response.text) self.assertIn('<html lang="de">', response.text)