Skip to content

Commit

Permalink
refactor(documentation-website): cleanup faq item (#779) (#1017)
Browse files Browse the repository at this point in the history
Fix "Non-interactive elements should not be assigned mouse or keyboard event listeners."
Fix "Use <input type="button">, <input type="image">, <input type="reset">, <input type="submit">, or <button> instead of the "button" role to ensure accessibility across all devices."
Fix "Elements with the 'button' interactive role must be focusable."
Fix "Visible, non-interactive elements with click handlers must have at least one keyboard listener."
  • Loading branch information
marikadeveloper committed May 6, 2024
1 parent c08e207 commit ba8acd4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
7 changes: 5 additions & 2 deletions documentation-website/src/components/faq-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
list-style-type: none;
width: 100%;

&:focus {
box-shadow: 0 0 2em var(--shadow);
& > button {
width: 100%;
&:focus {
box-shadow: 0 0 2em var(--shadow);
}
}

.accordion-section {
Expand Down
34 changes: 14 additions & 20 deletions documentation-website/src/components/faq-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,33 @@ const FaqItem = ({
setIsOpen(! isOpen,);
};

const handleKeyDown = (e: React.KeyboardEvent<HTMLLIElement>,) => {
if (e.key === 'Enter') {
toggleOpen();
}
};

return (
<li tabIndex={index + ONE} onKeyDown={handleKeyDown} className={'faq-item'}>
<div onClick={() => toggleOpen()} role="button">
<li className={ 'faq-item' }>
<button tabIndex={ index + ONE } onClick={ () => toggleOpen() }>
<div className="accordion-section">
<h2>
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
<Lang lnkey={`faq.questions.title_${ index + ONE }`} />
<Lang lnkey={ `faq.questions.title_${ index + ONE }` }/>
}
</h2>
{isOpen ?
{ isOpen ?
<span className="up-arrow"></span>
:
<span className="down-arrow"></span>
}
</div>
</div>
{isOpen &&
<p>
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
<Lang lnkey={`faq.questions.description_${ index + ONE }`} />
}
</p>
}
{ isOpen &&
<p>
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
<Lang lnkey={ `faq.questions.description_${ index + ONE }` }/>
}
</p>
}
</button>
</li>
);
};
Expand Down

0 comments on commit ba8acd4

Please sign in to comment.