* Fix typo in alt text * Convert unsemantic div into nav * Remove commented CSS * Refactor connect config menu to be more usable * Remove unused prop * Return focus to button when config menu collapses * Fix aria-label * Add aria-expanded and fix aria-label text Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Add transparent background-color to config menu button Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
import { h, Component, createRef } from 'preact';
|
|
// eslint-disable-next-line import/no-unresolved
|
|
import ConfigImage from 'images/overflow-horizontal.svg';
|
|
|
|
export class ConfigMenu extends Component {
|
|
constructor() {
|
|
super();
|
|
this.state = { visible: false };
|
|
this.firstNavLink = createRef();
|
|
this.configMenuButton = createRef();
|
|
}
|
|
|
|
handleClick = () => {
|
|
this.setState(
|
|
(prevState) => ({ visible: !prevState.visible }),
|
|
() => {
|
|
this.state.visible
|
|
? this.firstNavLink.current.focus()
|
|
: this.configMenuButton.current.focus();
|
|
},
|
|
);
|
|
};
|
|
|
|
render() {
|
|
const { visible } = this.state;
|
|
|
|
return (
|
|
<div className="chatchannels__config">
|
|
<button
|
|
onClick={this.handleClick}
|
|
aria-expanded={visible}
|
|
aria-label="configuration navigation menu"
|
|
style={{ backgroundImage: `url(${ConfigImage})` }}
|
|
ref={this.configMenuButton}
|
|
/>
|
|
{visible && (
|
|
<nav aria-label="configuration menu">
|
|
<ul className="chatchannels__configmenu">
|
|
<li>
|
|
<a href="/settings" ref={this.firstNavLink}>
|
|
Settings
|
|
</a>
|
|
</li>
|
|
<li>
|
|
<a href="/report-abuse">Report Abuse</a>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
}
|