Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #899 from solita/feature/ae-1763-nappainkohdistus
Browse files Browse the repository at this point in the history
AE-1763 Keyboard-navigable header menus
  • Loading branch information
muep authored Sep 26, 2022
2 parents 94ab46f + dac720d commit 78bbb58
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/pages/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as Navigation from '@Utility/navigation';
import * as Kayttajat from '@Utility/kayttajat';
import * as keys from '@Utility/keys';
import { _ } from '@Language/i18n';
import LanguageSelect from './language-select';
Expand All @@ -16,6 +17,15 @@
let nameNode;
let ohjeNode;
const toggleNameDropdown = () => (showNameDropdown = !showNameDropdown);
const toggleOhjeDropdown = () => (showOhjeDropdown = !showOhjeDropdown);
const enterHandler = handler => e => {
if (e.keyCode === keys.ENTER) {
handler();
}
};
const fullName = kayttaja => `${kayttaja.etunimi} ${kayttaja.sukunimi}`;
$: links = R.compose(
Expand Down Expand Up @@ -99,8 +109,10 @@
<div
bind:this={ohjeNode}
class="relative cursor-pointer hover:underline"
on:click={() => (showOhjeDropdown = !showOhjeDropdown)}>
<span> {$_('navigation.ohjeet')} </span>
on:click={toggleOhjeDropdown}>
<span tabindex="0" on:keydown={enterHandler(toggleOhjeDropdown)}>
{$_('navigation.ohjeet')}
</span>
<span class="material-icons absolute">keyboard_arrow_down</span>
{#if showOhjeDropdown}
<div
Expand Down Expand Up @@ -129,8 +141,8 @@
<div
bind:this={nameNode}
class="relative cursor-pointer hover:underline"
on:click={() => (showNameDropdown = !showNameDropdown)}>
<span>
on:click={toggleNameDropdown}>
<span tabindex="0" on:keydown={enterHandler(toggleNameDropdown)}>
{fullName(user)}
</span>
<span class="material-icons absolute">keyboard_arrow_down</span>
Expand Down

0 comments on commit 78bbb58

Please sign in to comment.