mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Improve a11y for the dropdown menu
Add role="button" to make the component report itself as a button. Add tabindex so the menu toggle can receive keyboard focus. Add keydown handlers for `<Enter>` and `<Space>` so the dropdown menu toggle responds to keyboard input. Set the aria-pressed attribute to true if the menu is open, or false if it is closed.
This commit is contained in:
@@ -3,7 +3,7 @@ A simplified dropdown component that doesn't rely on buttons as toggles like bo
|
||||
-->
|
||||
|
||||
<template lang="pug">
|
||||
.habitica-menu-dropdown.dropdown(@click="toggleDropdown()", :class="{open: isOpen}")
|
||||
.habitica-menu-dropdown.dropdown(@click="toggleDropdown()", @keypress.enter.space.stop.prevent="toggleDropdown()", role="button", tabindex="0", :class="{open: isOpen}", :aria-pressed="isPressed")
|
||||
.habitica-menu-dropdown-toggle
|
||||
slot(name="dropdown-toggle")
|
||||
.dropdown-menu(:class="{'dropdown-menu-right': right}")
|
||||
@@ -66,6 +66,9 @@ export default {
|
||||
if (this.openStatus !== undefined) return this.openStatus === 1 ? true : false;
|
||||
return this.isDropdownOpen;
|
||||
},
|
||||
isPressed () {
|
||||
return (this.isOpen ? 'true' : 'false');
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
document.documentElement.addEventListener('click', this._clickOutListener);
|
||||
|
||||
Reference in New Issue
Block a user